-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undo second namespace, post file on filefeed space creation #22
Conversation
WalkthroughThe update introduces Google Drive integration and refines the application's environment configuration. It notably adds the capability to fetch files from Google Drive, adjusts the handling of environment variables, and removes specific Flatfile configurations. Additionally, it enhances file management within spaces by leveraging Google Drive API and streamlines the codebase for better maintainability and readability. Changes
Possibly related issues
Recent Review DetailsConfiguration used: CodeRabbit UI Files ignored due to path filters (1)
Files selected for processing (9)
Additional comments not posted (7)
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling around the temporary file operations to ensure any issues during file creation or writing are appropriately managed.
try {
const tmpFile = await tmp.file({
prefix: "products-sample-data-",
postfix: ".csv",
});
fs.writeFileSync(tmpFile.path, response.data);
file = fs.createReadStream(tmpFile.path);
file.on("close", () => {
tmpFile.cleanup();
});
} catch (tmpError) {
console.error("Error handling temporary file: ", tmpError);
throw tmpError;
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
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; | |
} | |
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 | |
try { | |
const tmpFile = await tmp.file({ | |
prefix: "products-sample-data-", | |
postfix: ".csv", | |
}); | |
fs.writeFileSync(tmpFile.path, response.data); | |
file = fs.createReadStream(tmpFile.path); | |
file.on("close", () => { | |
tmpFile.cleanup(); | |
}); | |
} catch (tmpError) { | |
console.error("Error handling temporary file: ", tmpError); | |
throw tmpError; | |
} | |
return file; | |
} catch (err) { | |
console.log("fetchFileFromDrive error: ", err); | |
throw err; | |
} | |
} |
if (space.workflowType === WorkflowType.FileFeed) { | ||
const file = await fetchFileFromDrive(); | ||
await FlatfileService.postFileToSpace({ | ||
flatfileSpaceId: space.flatfileSpaceId, | ||
file, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling around the file fetching and posting process to enhance the robustness of the space creation functionality.
try {
const file = await fetchFileFromDrive();
await FlatfileService.postFileToSpace({
flatfileSpaceId: space.flatfileSpaceId,
file,
});
} catch (fileError) {
console.error("Error handling file feed workflow: ", fileError);
return new NextResponse("Error handling file feed workflow", { status: 500 });
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if (space.workflowType === WorkflowType.FileFeed) { | |
const file = await fetchFileFromDrive(); | |
await FlatfileService.postFileToSpace({ | |
flatfileSpaceId: space.flatfileSpaceId, | |
file, | |
}); | |
} | |
if (space.workflowType === WorkflowType.FileFeed) { | |
try { | |
const file = await fetchFileFromDrive(); | |
await FlatfileService.postFileToSpace({ | |
flatfileSpaceId: space.flatfileSpaceId, | |
file, | |
}); | |
} catch (fileError) { | |
console.error("Error handling file feed workflow: ", fileError); | |
return new NextResponse("Error handling file feed workflow", { status: 500 }); | |
} | |
} |
No description provided.