Better file api (#30)

* Better file api
This commit is contained in:
Jonas Plum
2022-01-23 04:27:31 +01:00
committed by GitHub
parent 8ca57c14d9
commit 2d817318f2
17 changed files with 105 additions and 521 deletions

View File

@@ -5422,46 +5422,6 @@ export const TicketsApiAxiosParamCreator = function (configuration?: Configurati
options: localVarRequestOptions,
};
},
/**
* Link files to an ticket. The files themself will be stored in object storage.
* @summary Link files to an ticket
* @param {number} id Ticket ID
* @param {Array<any>} files Added files
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
linkFiles: async (id: number, files: Array<any>, options: any = {}): Promise<RequestArgs> => {
// verify required parameter 'id' is not null or undefined
assertParamExists('linkFiles', 'id', id)
// verify required parameter 'files' is not null or undefined
assertParamExists('linkFiles', 'files', files)
const localVarPath = `/tickets/{id}/files`
.replace(`{${"id"}}`, encodeURIComponent(String(id)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
localVarHeaderParameter['Content-Type'] = 'application/json';
setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = serializeDataIfNeeded(files, localVarRequestOptions, configuration)
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary Link an ticket to an ticket
@@ -6141,18 +6101,6 @@ export const TicketsApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.getTicket(id, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Link files to an ticket. The files themself will be stored in object storage.
* @summary Link files to an ticket
* @param {number} id Ticket ID
* @param {Array<any>} files Added files
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async linkFiles(id: number, files: Array<any>, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<TicketWithTickets>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.linkFiles(id, files, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @summary Link an ticket to an ticket
@@ -6437,17 +6385,6 @@ export const TicketsApiFactory = function (configuration?: Configuration, basePa
getTicket(id: number, options?: any): AxiosPromise<TicketWithTickets> {
return localVarFp.getTicket(id, options).then((request) => request(axios, basePath));
},
/**
* Link files to an ticket. The files themself will be stored in object storage.
* @summary Link files to an ticket
* @param {number} id Ticket ID
* @param {Array<any>} files Added files
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
linkFiles(id: number, files: Array<any>, options?: any): AxiosPromise<TicketWithTickets> {
return localVarFp.linkFiles(id, files, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Link an ticket to an ticket
@@ -6739,19 +6676,6 @@ export class TicketsApi extends BaseAPI {
return TicketsApiFp(this.configuration).getTicket(id, options).then((request) => request(this.axios, this.basePath));
}
/**
* Link files to an ticket. The files themself will be stored in object storage.
* @summary Link files to an ticket
* @param {number} id Ticket ID
* @param {Array<any>} files Added files
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof TicketsApi
*/
public linkFiles(id: number, files: Array<any>, options?: any) {
return TicketsApiFp(this.configuration).linkFiles(id, files, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary Link an ticket to an ticket

View File

@@ -1425,34 +1425,7 @@ export default Vue.extend({
setupUppy: function(id: number) {
let uppy = new Uppy();
uppy.use(Tus, {
endpoint: location.protocol + '//' + location.hostname + ':'+ location.port + "/api/files/" + id.toString() + "/upload"
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
uppy.on("upload-success", (file: UppyFile, response: any) => {
if (this.ticket !== undefined) {
let files: Array<ModelFile> = [];
if (this.ticket.files) {
files = this.ticket.files;
}
let regex = /\/([^/]*)\+[^/]*$/;
let matches = response.uploadURL.match(regex);
if (matches.length != 2) {
return;
}
console.log(matches[1]);
files.push({ name: file.name, key: matches[1] });
API.linkFiles(id, files)
.then(response => {
this.$store.dispatch("alertSuccess", { name: "File added" });
this.setTicket(response.data);
})
.catch(error => {
this.$store.dispatch("alertError", { name: "File not added", detail: error });
});
}
endpoint: location.protocol + '//' + location.hostname + ':'+ location.port + "/api/files/" + id.toString() + "/tusd"
});
return uppy;
},