started cleaning up code
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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,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,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;
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user