mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 02:13:51 -04:00
* Add new cli * Remove old readme * Add documentation to readme file * Add github workflow tests for cli * Fix typo in docs * Add usage info to readme * Add package-lock.json * Fix tsconfig * Cleanup * Fix lint * Cleanup package.json * Fix accidental server change * Remove rootdir from cli * Remove tsbuildinfo * Add prettierignore * Make CLI use internal openapi specs * Add ignore and dry-run features * Sort paths alphabetically * Don't remove substring * Remove shorthand for delete * Remove unused import * Remove chokidar * Set correct openapi cli generator script * Add progress bar * Rename target to asset * Add deletion progress bar * Ignore require statement * Use read streams instead of readfile * Fix github feedback * Fix upload requires * More github comments * Cleanup messages * Cleaner pattern concats * Github comments --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import axios, { AxiosRequestConfig } from 'axios';
|
|
import FormData from 'form-data';
|
|
import { ApiConfiguration } from '../cores/api-configuration';
|
|
|
|
export class UploadService {
|
|
private readonly uploadConfig: AxiosRequestConfig<any>;
|
|
private readonly checkAssetExistenceConfig: AxiosRequestConfig<any>;
|
|
private readonly importConfig: AxiosRequestConfig<any>;
|
|
|
|
constructor(apiConfiguration: ApiConfiguration) {
|
|
this.uploadConfig = {
|
|
method: 'post',
|
|
maxRedirects: 0,
|
|
url: `${apiConfiguration.instanceUrl}/asset/upload`,
|
|
headers: {
|
|
'x-api-key': apiConfiguration.apiKey,
|
|
},
|
|
maxContentLength: Number.POSITIVE_INFINITY,
|
|
maxBodyLength: Number.POSITIVE_INFINITY,
|
|
};
|
|
|
|
this.importConfig = {
|
|
method: 'post',
|
|
maxRedirects: 0,
|
|
url: `${apiConfiguration.instanceUrl}/asset/import`,
|
|
headers: {
|
|
'x-api-key': apiConfiguration.apiKey,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
maxContentLength: Number.POSITIVE_INFINITY,
|
|
maxBodyLength: Number.POSITIVE_INFINITY,
|
|
};
|
|
|
|
this.checkAssetExistenceConfig = {
|
|
method: 'post',
|
|
maxRedirects: 0,
|
|
url: `${apiConfiguration.instanceUrl}/asset/bulk-upload-check`,
|
|
headers: {
|
|
'x-api-key': apiConfiguration.apiKey,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
};
|
|
}
|
|
|
|
public checkIfAssetAlreadyExists(path: string, checksum: string): Promise<any> {
|
|
this.checkAssetExistenceConfig.data = JSON.stringify({ assets: [{ id: path, checksum: checksum }] });
|
|
|
|
// TODO: retry on 500 errors?
|
|
return axios(this.checkAssetExistenceConfig);
|
|
}
|
|
|
|
public upload(data: FormData): Promise<any> {
|
|
this.uploadConfig.data = data;
|
|
|
|
// TODO: retry on 500 errors?
|
|
return axios(this.uploadConfig);
|
|
}
|
|
|
|
public import(data: any): Promise<any> {
|
|
this.importConfig.data = data;
|
|
|
|
// TODO: retry on 500 errors?
|
|
return axios(this.importConfig);
|
|
}
|
|
}
|