1.0.3 • Published 2 years ago

wrap-gyazo v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

wrap-gyazo

Gyazo API wrapper made in TypeScript.
*For now, only upload feature.

Installation

npm i wrap-gyazo

Register an application with Gyazo.

Authorize (Optional)

*If you want to get an access token for each user.

  1. Get client_id, secret_id and Callback URL in Gyazo Applications.
  2. Generate a link for approval.
import {GyazoAdmin} from 'wrap-gyazo';
const gyazoAdmin = new GyazoAdmin({
  clientId:"***************",
  redirectUri:"***************",
  clientSecret:"***************"
});
const authUrl = gyazoAdmin.makeAuthorizeURL();
/**
 * authUrl = {url:string,state:string}
 */

【Optional】 Please use the "state" parameter to prevent CSRF.
*The "state" parameter is uuidv4.

  1. The user accesses the generated URL and approves the app.
    1. Get the "code" and "state" parameters from the callback URL.
    2. 【Optional】 Check the state parameter.
    3. Get "access_token" from "code".
    const accessToken =  await gyazoAdmin.getAccessToken(code);

Upload

Preparation

  1. Get the user access token or the application access token.
  2. Load an image data.

Upload to Gyazo

//base64
const uploadRes = await gyazoAdmin.uploadBase64(accessToken,base64);
//buffer
const uploadRes = await gyazoAdmin.uploadBuffer(accessToken,imageData,"png")

*You can't upload from a browser, because of the CORS policy

Others

File/Blob->Base64 Conversion (Browser Only)

import {readAsDataURL} from 'wrap-gyazo';

const base64 = await readAsDataURL(file);

Thanks for the Reference

Pull Request

If you want to add a feature, please submit a pull request.

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago