Created
January 27, 2019 14:47
-
-
Save ogawa0071/697b7e7863f58a172196584ff4f88c35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs"); | |
| const child_process = require("child_process") | |
| const main = async () => { | |
| const domainGSuite = ''; | |
| const _user = JSON.parse((await fs.promises.readFile("_user.json", { encoding: "utf8" }))) | |
| const user = JSON.parse(await fs.promises.readFile("user.json", { encoding: "utf8" })) | |
| // const __domain = JSON.parse(await fs.promises.readFile("__domain.json", {encoding: "utf8"})) | |
| const _domain = JSON.parse(await fs.promises.readFile("_domain.json", { encoding: "utf8" })) | |
| const domain = JSON.parse(await fs.promises.readFile("domain.json", { encoding: "utf8" })) | |
| let files = [] | |
| // _user.forEach((path) => { | |
| _domain.forEach((path) => { | |
| // const fileArray = user.filter((file) => { | |
| const fileArray = domain.filter((file) => { | |
| if (file.path === path[0]) { | |
| return file; | |
| } | |
| }) | |
| if (fileArray.length !== 0) { | |
| const file = fileArray[0] | |
| // let exist = [] | |
| // for (const name of __domain) { | |
| // if (file.name === name) { | |
| // exist.push(exist) | |
| // } | |
| // } | |
| // if (exist.length === 0) { | |
| files.push(file) | |
| // } | |
| } | |
| }) | |
| // console.log(files) | |
| const names = []; | |
| // files.forEach((file) => { | |
| for (const file of files) { | |
| if (file.mimeType === "application/vnd.google-apps.document") { | |
| // child_process.exec(`open https://docs.google.com/document/u/3/d/${file.id}/export?format=docx`) | |
| // child_process.exec(`open https://drive.google.com/a/${domainGSuite}/open?id=${file.id}`) | |
| names.push([`${file.name}.docx`, `${file.path}.docx`]) | |
| } else if (file.mimeType === "application/vnd.google-apps.spreadsheet") { | |
| // child_process.exec(`open https://docs.google.com/spreadsheets/u/3/d/${file.id}/export?format=xlsx`) | |
| // child_process.exec(`open https://drive.google.com/a/${domainGSuite}/open?id=${file.id}`) | |
| names.push([`${file.name}.xlsx`, `${file.path}.xlsx`]) | |
| } else if (file.mimeType === "application/vnd.google-apps.presentation") { | |
| // child_process.exec(`open https://docs.google.com/presentation/u/3/d/${file.id}/export/pptx`) | |
| // child_process.exec(`open https://drive.google.com/a/${domainGSuite}/open?id=${file.id}`) | |
| names.push([`${file.name}.pptx`, `${file.path}.pptx`]) | |
| } else { | |
| // child_process.exec(`open https://drive.google.com/uc?id=${file.id}&authuser=3&export=download`) | |
| // child_process.exec(`open https://drive.google.com/a/${domainGSuite}/open?id=${file.id}`) | |
| names.push([`${file.name}`, `${file.path}`]) | |
| } | |
| // await new Promise((resolve, reject) => { | |
| // setTimeout(() => { | |
| // resolve() | |
| // }, 10000) | |
| // }) | |
| // }) | |
| } | |
| console.log(JSON.stringify(names)); | |
| } | |
| main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs"); | |
| const main = async () => { | |
| // const corpora = "user"; | |
| const corpora = "domain"; | |
| const files = JSON.parse(await fs.promises.readFile(`./_${corpora}.json`, { encoding: "utf8" })) | |
| console.log(files); | |
| for (const file of files) { | |
| console.log(file[0]); | |
| const path = /(.*)(\/)(.*)/.exec(file[0]) | |
| if (path) { | |
| const name = path[3] | |
| const directory = path[1] | |
| try { | |
| await fs.promises.readdir(`./googledrive-to-dropbox/${corpora}${directory}`.replace(/(\s+)/g, '\$1')) | |
| } catch { | |
| await fs.promises.mkdir(`./googledrive-to-dropbox/${corpora}${directory}`.replace(/(\s+)/g, '\$1'), { | |
| recursive: true, | |
| }) | |
| } | |
| } else { | |
| throw new Error(`path: ${file}`) | |
| } | |
| try { | |
| // docx | |
| await fs.promises.copyFile(`./${corpora}${file[1]}.docx`.replace(/(\s+)/g, '\$1'), `./googledrive-to-dropbox/${corpora}${file[0]}.docx`.replace(/(\s+)/g, '\$1')) | |
| } catch (error) { | |
| console.log(error) | |
| try { | |
| // .xlsx | |
| await fs.promises.copyFile(`./${corpora}${file[1]}.xlsx`.replace(/(\s+)/g, '\$1'), `./googledrive-to-dropbox/${corpora}${file[0]}.xlsx`.replace(/(\s+)/g, '\$1')) | |
| } catch (error) { | |
| console.log(error) | |
| try { | |
| // .pptx | |
| await fs.promises.copyFile(`./${corpora}${file[1]}.pptx`.replace(/(\s+)/g, '\$1'), `./googledrive-to-dropbox/${corpora}${file[0]}.pptx`.replace(/(\s+)/g, '\$1')) | |
| } catch (error) { | |
| console.log(error) | |
| try { | |
| // Default | |
| await fs.promises.copyFile(`./${corpora}${file[1]}`.replace(/(\s+)/g, '\$1'), `./googledrive-to-dropbox/${corpora}${file[0]}`.replace(/(\s+)/g, '\$1')) | |
| } catch (error) { | |
| // Error | |
| throw new Error(error) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment