Skip to content

Commit

Permalink
Add option to make uploads private
Browse files Browse the repository at this point in the history
  • Loading branch information
nishithkhanna authored and out386 committed Jul 17, 2019
1 parent e23b90c commit c931492
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/.constants.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module.exports = Object.freeze({
SUDO_USERS: [012, 345], // Telegram user IDs. These users can use the bot in any chat.
AUTHORIZED_CHATS: [678, 901], // Telegram chat IDs. Anyone in these chats can use the bot.
STATUS_UPDATE_INTERVAL_MS: 12000, // A smaller number will update faster, but might cause rate limiting
DRIVE_FILE_PRIVATE: {
enabled: false,
email: 'somemail@gmail.com'
},
DOWNLOAD_NOTIFY_TARGET: { // Information about the web service to notify on download completion.
enabled: false, // Set this to true to use the notify functionality
host: 'hostname.domain',
Expand Down
19 changes: 15 additions & 4 deletions src/drive/drive-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import driveAuth = require('./drive-auth');
import driveFile = require('./upload-file');
import utils = require('./drive-utils');
import { google, drive_v3 } from 'googleapis';
import constants = require('../.constants.js');


export function uploadFileOrFolder(filePath: string, mime: string, parent: string, size:number, callback: (err: string, id: string) => void) {
Expand Down Expand Up @@ -51,14 +52,24 @@ export function getSharableLink(fileId:string, isFolder:boolean, callback: (err:
return;
}
const drive = google.drive({ version: 'v3', auth });
var resource;
if (constants.DRIVE_FILE_PRIVATE && constants.DRIVE_FILE_PRIVATE.enabled) {
resource = {
role: 'reader',
type: 'user',
emailAddress: constants.DRIVE_FILE_PRIVATE.email
};
} else {
resource = {
role: 'reader',
type: 'anyone'
};
}

drive.permissions.create({
fileId: fileId,
// @ts-ignore Unknown property error
resource: {
role: 'reader',
type: 'anyone'
}
resource: resource
},
(err:Error, res:any) => {
if (err) {
Expand Down

0 comments on commit c931492

Please sign in to comment.