-
Notifications
You must be signed in to change notification settings - Fork 2
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
5 appwrite apiauth #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from "react"; | ||
import Uppy, { type UploadResult, UppyFile } from "@uppy/core"; | ||
import AwsS3, { type AwsS3UploadParameters } from "@uppy/aws-s3"; | ||
import { Dashboard } from "@uppy/react"; | ||
import { sha256 } from "crypto-hash"; | ||
|
||
// Uppy styles | ||
import "@uppy/core/dist/style.min.css"; | ||
import "@uppy/dashboard/dist/style.min.css"; | ||
|
||
export async function getUploadParameters(file: UppyFile) { | ||
const arrayBuffer = await new Response(file.data).arrayBuffer(); | ||
const response = await fetch("/api/upload", { | ||
method: "POST", | ||
headers: { | ||
accept: "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
filename: file.name, | ||
fileHash: await sha256(arrayBuffer), | ||
contentType: file.type, | ||
}), | ||
}); | ||
if (!response.ok) throw new Error("Unsuccessful request"); | ||
|
||
// Parse the JSON response. | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const data: { url: string; method: "PUT" } = await response.json(); | ||
|
||
// Return an object in the correct shape. | ||
const object: AwsS3UploadParameters = { | ||
method: data.method, | ||
url: data.url, | ||
fields: {}, // For presigned PUT uploads, this should be left empty. | ||
// Provide content type header required by S3 | ||
headers: { | ||
"Content-Type": file.type ? file.type : "application/octet-stream", | ||
}, | ||
}; | ||
return object; | ||
} | ||
|
||
export function FileUploader({ | ||
onUploadSuccess, | ||
}: { | ||
onUploadSuccess: (result: UploadResult) => void; | ||
}) { | ||
const uppy = React.useMemo(() => { | ||
const uppy = new Uppy({ | ||
autoProceed: true, | ||
restrictions: { | ||
maxNumberOfFiles: 3, | ||
}, | ||
}).use(AwsS3, { | ||
id: "AwsS3", | ||
getUploadParameters: (file: UppyFile) => getUploadParameters(file), | ||
}); | ||
return uppy; | ||
}, []); | ||
uppy.on("complete", (result) => { | ||
onUploadSuccess(result); | ||
}); | ||
return <Dashboard uppy={uppy} showLinkToFileUploadResult={true} />; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Review:
Overall, the code looks well-structured and functional. Consider the suggestions above to enhance maintainability, readability, and security aspects. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { createContext, useContext, useEffect, useState } from "react"; | |
import { IUser } from "@/types"; | ||
import { getCurrentUser } from "@/lib/appwrite/api"; | ||
|
||
// initial user | ||
export const INITIAL_USER = { | ||
id: "", | ||
name: "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code patch you provided seems to be a declaration of Code Review:Potential Issues:
Potential Improvements:
By addressing these, the code will be more robust, maintainable, and less prone to unexpected behavior. |
||
|
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.
The code patch you provided changes the
OPENAI_API_ENDPOINT
value fromhttps://api.openai.com/v1
tohttps://aihubmix.com/v1
. Here are some observations and suggestions:Potential Issue: Endpoint Change: While changing the API endpoint, ensure that
https://aihubmix.com/v1
is a valid and authorized endpoint for your API calls. Confirm that it is correctly set up to handle OpenAI requests.Security Warning: Make sure that the new
OPENAI_API_ENDPOINT
(https://aihubmix.com/v1
) supports secure HTTPS connections to protect data transmitted between your system and the endpoint.Configuration Documentation: Update the comment to reflect the current
OPENAI_API_ENDPOINT
. It's beneficial for maintenance and understanding of the configuration in the future.Code Comments: Consider providing an example or brief explanation in the
PROMPT
field to help users understand its purpose or what kind of input is expected.Version Control: Ensure that the changes are reviewed by team members before merging into the main branch, especially if this file is shared among multiple developers.
Testing Changes: After updating the API endpoint, test the functionality thoroughly to ensure that the integration still works as expected with the new endpoint.
Consistent Naming: Maintain naming consistency across different variables (for example,
OPENAI_API_ENDPOINT
uses underscores; ensure other variables follow the same convention for readability).Logging and Monitoring: Implement proper logging mechanisms to track API requests/responses when communicating with the new endpoint.
To conclude, verify the validity of the new endpoint, update documentation/comment as necessary, maintain security standards, and perform thorough testing before finalizing these changes.