npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sheetbase/drive

v1.1.0

Published

File management with Drive for Sheetbase backend app.

Downloads

8

Readme

Sheetbase Module: @sheetbase/drive

File management with Drive for Sheetbase backend app.

Build Status Coverage Status NPM License clasp Support me on Patreon PayPal Ask me anything

Install

Using npm: npm install --save @sheetbase/drive

import * as Drive from "@sheetbase/drive";

As a library: 1mbpy4unOm6RTKzU_awPJnt9mNncpFPXR9f3redN5YavB8PSYUDKe8Fo8

Set the Indentifier to DriveModule and select the lastest version, view code.

declare const DriveModule: { Drive: any };
const Drive = DriveModule.Drive;

Scopes

https://www.googleapis.com/auth/drive

Usage

  • Docs homepage: https://sheetbase.github.io/drive

  • API reference: https://sheetbase.github.io/drive/api

Getting started

Install: npm install --save @sheetbase/drive

Usage:

import { drive } from "@sheetbase/drive";

const Drive = drive({
  uploadFolder: "1Abc..."
  /* configs */
});

const file = Drive.uploadFile({
  name: "file.txt",
  base64Value: "data:text/plain;base64,Abc=="
});

Configs

Drive module configurations.

export interface Options extends Intergration {
  // the upload folder id
  uploadFolder: string;
  // limits
  allowTypes?: string[]; // mimetype list
  maxSize?: number; // MB = 1,000,000 bytes
  // structured by: <year>/<month>
  nested?: boolean;
  // customize the response url
  urlBuilder?: string[] | { (id: string): string };
}

export interface Intergration {
  AuthToken?: any;
}

uploadFolder (required)

  • Type: string
  • Default: REQUIRED

The Upload folder id.

urlBuilder

  • Type: string[] or Function
  • Default: ['https://drive.google.com/uc?id=']

Customize the file url.

nested

  • Type: boolean
  • Default: undefined

Put upload file in Wordpress-like upload structure <year>/<month>.

allowTypes

  • Type: string[]
  • Default: undefined

Use this if you want to accept certain types of file. Since the file is stored in Google Drive, there is no need to worry about script execution security. But uploader can upload any malicious file, these files may harm downloader devices.

maxSize

  • Type: number
  • Default: 10

Upload file size limit in MB.

Drive

Interface for file management in Drive.

  • setIntegration: Integrate with other services
  • getFileById: Get a file
  • getFileInfoById: Get a file information
  • uploadFile: Upload a file
  • uploadFiles: Upload multiple files
  • updateFile: Update a file
  • removeFile: Delete a file

Drive service detail:

class DriveService {
  setIntegration<K extends keyof Intergration, Value>(
    key: K,
    value: Value
  ): DriveService;
  registerRoutes(options: AddonRoutesOptions): void;
  base64Parser(
    base64Value: string
  ): {
    mimeType: string;
    size: number;
    base64Body: string;
  };
  isFileAvailable(file: GoogleAppsScript.Drive.File): boolean;
  isFileShared(file: GoogleAppsScript.Drive.File): boolean;
  isValidFileType(mimeType: string): boolean;
  isValidFileSize(sizeBytes: number): boolean;
  getSharingPreset(preset: SharingPreset): SharingConfig;
  generateFileName(fileName: string, rename?: RenamePolicy): string;
  buildFileUrl(id: string): string;
  getFileInfo(file: GoogleAppsScript.Drive.File): FileInfo;
  getFilesInfo(files: GoogleAppsScript.Drive.File[]): FileInfo[];
  getUploadFolder(): GoogleAppsScript.Drive.Folder;
  getOrCreateFolderByName(
    name: string,
    parentFolder?: GoogleAppsScript.Drive.Folder
  ): GoogleAppsScript.Drive.Folder;
  createFolderByYearAndMonth(
    parentFolder?: GoogleAppsScript.Drive.Folder
  ): GoogleAppsScript.Drive.Folder;
  createFileFromBase64Body(
    parentFolder: GoogleAppsScript.Drive.Folder,
    fileName: string,
    mimeType: string,
    base64Body: string
  ): GoogleAppsScript.Drive.File;
  setFileSharing(
    file: GoogleAppsScript.Drive.File,
    sharing?: FileSharing
  ): GoogleAppsScript.Drive.File;
  setEditPermissionForUser(
    file: GoogleAppsScript.Drive.File,
    auth: {
      uid?: string;
      email?: string;
    }
  ): GoogleAppsScript.Drive.File;
  hasViewPermission(file: GoogleAppsScript.Drive.File): boolean;
  hasEditPermission(file: GoogleAppsScript.Drive.File): boolean;
  getFileById(id: string): GoogleAppsScript.Drive.File;
  getFileInfoById(id: string): FileInfo;
  uploadFile(
    fileData: UploadFile,
    customFolder?: string,
    renamePolicy?: RenamePolicy,
    sharing?: FileSharing
  ): GoogleAppsScript.Drive.File;
  uploadFiles(uploadResources: UploadResource[]): GoogleAppsScript.Drive.File[];
  updateFile(id: string, data?: FileUpdateData): GoogleAppsScript.Drive.File;
  removeFile(id: string): GoogleAppsScript.Drive.File;
}

Routes

To add routes to your app, see options AddonRoutesOptions:

Drive.registerRoutes(options?: AddonRoutesOptions);

Default disabled

Disabled routes by default, to enable set { disabledRoutes: [] } in registerRoutes():

[
  "put:/storage" // upload files
  "post:/storage" // update a file
  "delete:/storage" // delete a file
];

Endpoints

GET /storage

Get a file info. Route query:

  • id: The file id

PUT /storage

Upload a file or multiple files. Route body:

  • file: Single file upload data, (UploadFile)
  • folder: Custom folder (for single file)
  • rename: Naming policy (for single file)
  • share: Sharing option (for single file)
  • files: Multiple files upload data, (UploadResource[])

Upload a file.

{
  file: {
    name: 'file.txt',
    base64Value: '...'
  }
}

Upload to a custom folder.

{
  file: {/* ... */},
  folder: 'My folder'
}

Rename upload file.

{
  file: {/* ... */},
  rename: 'AUTO', // AUTO | HASH
}

Custom file sharing.

{
  file: {/* ... */},
  share: 'PUBLIC' // PRIVATE (default) | PUBLIC | { access: '', permission: '' }
}

Upload multiple files.

{
  files: [
    {
      file: {
        name: "file.txt",
        base64Value: "..."
      }
    },
    {
      file: {
        name: "files.txt",
        base64Value: "..."
      }
    }
  ];
}

POST /storage

Update a file information or sharing. Route body:

  • id: The file id
  • data: Update data
// Update data
{
  name: '...', // change the file name
  description: '...', // change the file description
  content: '...', // change the file content
  sharing: '...', // change the file sharing
}

DELETE /storage

Trash a file. Route body:

  • id: The file id

License

@sheetbase/drive is released under the MIT license.