fix: improve the uploading speed by reducing the API call.

This commit is contained in:
Yufan Sheng 2024-07-08 22:29:15 +08:00
parent d1a0943b33
commit 12f6075bc9
Signed by: syhily
GPG Key ID: DEB186763C308C31
2 changed files with 25 additions and 6 deletions

View File

@ -34,6 +34,19 @@ export default defineConfig({
})
```
### Vite Dependency Optimization
If you have issues like '' in using this tool. Remember to change your Astro configuration for add the code shown below.
```ts
export default defineConfig({
vite: {
// Add this for avoiding the needless import optimize in Vite.
optimizeDeps: { exclude: ['opendal'] },
},
});
```
## Options
```ts

View File

@ -96,17 +96,23 @@ class Uploader {
}
async isExist(key: string, size: number): Promise<boolean> {
const exist = await this.operator.isExist(key);
if (exist) {
const { contentLength } = await this.operator.stat(key);
try {
const { contentLength, isFile } = await this.operator.stat(key);
if ((contentLength !== null && contentLength !== BigInt(size)) || this.override) {
await this.operator.delete(key);
return false;
}
return true;
return isFile();
} catch (err) {
// Just ignore the error for now. If we find better solution for how to handle the opendal error.
if (err instanceof Error) {
const msg = err.toString();
if (msg.includes('Error: NotFound')) {
return false;
}
}
throw err;
}
return false;
}
async write(key: string, body: Buffer) {