started cleaning up code

This commit is contained in:
kyle hoell
2020-11-25 13:15:27 -05:00
parent df1a488e21
commit cadc7b9548
6 changed files with 54 additions and 21 deletions
+34
View File
@@ -0,0 +1,34 @@
import {UserInterface} from "../../../models/user";
import env from "../../../enviroment/env";
import { google } from "googleapis";
import getGoogleAuth from "../../../db/googleAuth";
import createQueryGoogle, {googleQueryType} from "../../../utils/createQueryGoogle";
const fields = 'id, name, size, modifiedTime, hasThumbnail, parents, mimeType, thumbnailLink, webViewLink, shared';
class GoogleDbUtil {
constructor() {
}
getList = async(query: googleQueryType, user: UserInterface) => {
const oauth2Client = await getGoogleAuth(user);
const limit = query.limit;
let parent = query.parent === "/" ? "root" : query.parent;
const {queryBuilder, orderBy} = createQueryGoogle(query, parent)
const previosPageToken = query.pageToken;
const drive = google.drive({version:"v3", auth: oauth2Client});
const files = await drive.files.list({pageSize: limit, fields: `nextPageToken, files(${fields})`, q: queryBuilder, orderBy, pageToken: previosPageToken});
return files
}
}
export default GoogleDbUtil;
+1 -1
View File
@@ -205,7 +205,7 @@ export interface UserInterface extends Document {
changeEncryptionKey: (randomKey: Buffer) => void;
generateEmailVerifyToken: () => string;
generatePasswordResetToken: () => string;
encryptDriveIDandKey: (ID:string, key: string) => void;
encryptDriveIDandKey: (ID:string, key: string) => Promise<void>;
decryptDriveIDandKey: () => {clientID: string, clientKey: string};
encryptDriveTokenData: (token: Object) => void;
decryptDriveTokenData: () => any;
+11 -18
View File
@@ -13,6 +13,10 @@ import uuid from "uuid";
import getBusboyData from "../ChunkService/utils/getBusboyData";
import axios from "axios";
import awaitUploadGoogle from "../ChunkService/utils/awaitUploadGoogle";
import {googleQueryType} from "../../utils/createQueryGoogle";
import GoogleDbUtils from "../../db/utils/googleFileUtils";
const googleDbUtils = new GoogleDbUtils();
interface RequestType extends Request {
user?: UserInterface,
@@ -30,22 +34,11 @@ class GoogleFileService {
}
getList = async(user: UserInterface, query: any) => {
getList = async(user: UserInterface, query: googleQueryType) => {
const oauth2Client = await getGoogleAuth(user);
const files = await googleDbUtils.getList(query, user);
const limit: any = query.limit as any;
let parent = query.parent === "/" ? "root" : query.parent;
const {queryBuilder, orderBy} = createQueryGoogle(query, parent)
const previosPageToken: any = query.pageToken;
const drive = google.drive({version:"v3", auth: oauth2Client});
const files = await drive.files.list({pageSize: limit, fields: `nextPageToken, files(${fields})`, q: queryBuilder, orderBy, pageToken: previosPageToken});
const nextPageToken: any = files.data.nextPageToken;
const nextPageToken = files.data.nextPageToken;
const userID = user._id;
@@ -54,22 +47,22 @@ class GoogleFileService {
return convertedFiles;
}
getMongoGoogleList = async(user: UserInterface, query: any) => {
getMongoGoogleList = async(user: UserInterface, query: googleQueryType) => {
const oauth2Client = await getGoogleAuth(user);
const limit: any = query.limit as any;
const limit = query.limit;
let parent = query.parent === "/" ? "root" : query.parent;
const {queryBuilder, orderBy} = createQueryGoogle(query, parent)
const previosPageToken: any = query.pageToken;
const previosPageToken = query.pageToken;
const drive = google.drive({version:"v3", auth: oauth2Client});
const files = await drive.files.list({pageSize: limit, fields: `nextPageToken, files(${fields})`, q: queryBuilder, orderBy, pageToken: previosPageToken});
const nextPageToken: any = files.data.nextPageToken;
const nextPageToken = files.data.nextPageToken;
const userID = user._id;
+1 -1
View File
@@ -1,6 +1,6 @@
import convertDriveToMongo from "./convertDriveToMongo";
const convertDriveListToMongoList = (driveObjs: any, ownerID:string, pageToken?: string) => {
const convertDriveListToMongoList = (driveObjs: any, ownerID:string, pageToken?: string | null | undefined) => {
let convertedObjs = [];
+1 -1
View File
@@ -1,6 +1,6 @@
import videoChecker from "./videoChecker";
const convertDriveToMongo = (driveObj: any, ownerID: string, pageToken?: string) => {
const convertDriveToMongo = (driveObj: any, ownerID: string, pageToken?: string | undefined | null) => {
let convertedObj: any = {};
convertedObj._id = driveObj.id;
+6
View File
@@ -25,4 +25,10 @@ const createQueryGoogle = (query: any, parent: any) => {
return {queryBuilder, orderBy}
}
export interface googleQueryType {
limit: number,
parent: string,
pageToken: string,
}
export default createQueryGoogle;