fix: improve the uploading speed by reducing the API call.
This commit is contained in:
parent
d1a0943b33
commit
12f6075bc9
13
README.md
13
README.md
@ -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
|
## Options
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
18
src/index.ts
18
src/index.ts
@ -96,17 +96,23 @@ class Uploader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async isExist(key: string, size: number): Promise<boolean> {
|
async isExist(key: string, size: number): Promise<boolean> {
|
||||||
const exist = await this.operator.isExist(key);
|
try {
|
||||||
if (exist) {
|
const { contentLength, isFile } = await this.operator.stat(key);
|
||||||
const { contentLength } = await this.operator.stat(key);
|
|
||||||
if ((contentLength !== null && contentLength !== BigInt(size)) || this.override) {
|
if ((contentLength !== null && contentLength !== BigInt(size)) || this.override) {
|
||||||
await this.operator.delete(key);
|
await this.operator.delete(key);
|
||||||
return false;
|
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) {
|
async write(key: string, body: Buffer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user