mirror of
https://github.com/penxio/penx.git
synced 2026-04-19 03:03:06 -04:00
28 lines
626 B
TypeScript
28 lines
626 B
TypeScript
import { calculateSHA256FromFile } from './calculateSHA256FromFile'
|
|
import { uploadToGoogleDrive } from './uploadToGoogleDrive'
|
|
|
|
type UploadReturn = {
|
|
contentDisposition: string
|
|
contentType: string
|
|
pathname: string
|
|
url: string
|
|
}
|
|
|
|
export async function uploadFile(
|
|
file: File,
|
|
isUploadToGoogleDrive: boolean = true,
|
|
) {
|
|
const fileHash = await calculateSHA256FromFile(file)
|
|
|
|
const res = await fetch(`/api/upload?fileHash=${fileHash}`, {
|
|
method: 'POST',
|
|
body: file,
|
|
}).then((res) => res.json())
|
|
|
|
if (isUploadToGoogleDrive) {
|
|
uploadToGoogleDrive(fileHash, file)
|
|
}
|
|
|
|
return res as UploadReturn
|
|
}
|