-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Undo second namespace, post file on filefeed space creation (#22)
- Loading branch information
1 parent
7d87904
commit 2c5980b
Showing
10 changed files
with
299 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import fs from "fs"; | ||
import tmp from "tmp-promise"; | ||
|
||
const { google } = require("googleapis"); | ||
|
||
export const fetchFileFromDrive = async (): Promise<fs.ReadStream> => { | ||
const service = google.drive({ | ||
version: "v3", | ||
auth: process.env.GOOGLE_DRIVE_API_KEY, | ||
}); | ||
|
||
let file; | ||
|
||
try { | ||
const response = await service.files.get({ | ||
fileId: process.env.GOOGLE_DRIVE_FILE_ID, | ||
alt: "media", | ||
}); | ||
|
||
// Create a temporary file and write the data into it | ||
const tmpFile = await tmp.file({ | ||
prefix: "products-sample-data-", | ||
postfix: ".csv", | ||
}); | ||
fs.writeFileSync(tmpFile.path, response.data); | ||
|
||
// Create a fs.ReadStream from the temporary file | ||
file = fs.createReadStream(tmpFile.path); | ||
|
||
// When you're done with the file, close and unlink it | ||
file.on("close", () => { | ||
tmpFile.cleanup(); | ||
}); | ||
|
||
return file; | ||
} catch (err) { | ||
console.log("fetchFileFromDrive error: ", err); | ||
throw err; | ||
} | ||
}; |
This file contains 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
This file contains 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
Oops, something went wrong.