Skip to content

Commit d19bf96

Browse files
committed
Implemented delete file api route and model
1 parent 1ee15fe commit d19bf96

6 files changed

Lines changed: 296 additions & 0 deletions

File tree

‎src/internal/apis/FileDeleteApi.ts‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* Juno
5+
* Juno Public API Docs
6+
*
7+
* The version of the OpenAPI document: 1.0
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
import * as runtime from '../runtime';
16+
import type { DeleteFilesModel, DeleteFilesResponse } from '../models/index';
17+
import {
18+
DeleteFilesModelFromJSON,
19+
DeleteFilesModelToJSON,
20+
DeleteFilesResponseFromJSON,
21+
DeleteFilesResponseToJSON,
22+
} from '../models/index';
23+
24+
export interface FileDeleteControllerDeleteFilesRequest {
25+
deleteFilesModel: DeleteFilesModel;
26+
}
27+
28+
/**
29+
*
30+
*/
31+
export class FileDeleteApi extends runtime.BaseAPI {
32+
/**
33+
* Delete files from a bucket
34+
*/
35+
async fileDeleteControllerDeleteFilesRaw(
36+
requestParameters: FileDeleteControllerDeleteFilesRequest,
37+
initOverrides?: RequestInit | runtime.InitOverrideFunction
38+
): Promise<runtime.ApiResponse<DeleteFilesResponse>> {
39+
if (requestParameters['deleteFilesModel'] == null) {
40+
throw new runtime.RequiredError(
41+
'deleteFilesModel',
42+
'Required parameter "deleteFilesModel" was null or undefined when calling fileDeleteControllerDeleteFiles().'
43+
);
44+
}
45+
46+
const queryParameters: any = {};
47+
48+
const headerParameters: runtime.HTTPHeaders = {};
49+
50+
headerParameters['Content-Type'] = 'application/json';
51+
52+
if (this.configuration && this.configuration.accessToken) {
53+
const token = this.configuration.accessToken;
54+
const tokenString = await token('API_Key', []);
55+
56+
if (tokenString) {
57+
headerParameters['Authorization'] = `Bearer ${tokenString}`;
58+
}
59+
}
60+
const response = await this.request(
61+
{
62+
path: `/file/delete`,
63+
method: 'DELETE',
64+
headers: headerParameters,
65+
query: queryParameters,
66+
body: DeleteFilesModelToJSON(requestParameters['deleteFilesModel']),
67+
},
68+
initOverrides
69+
);
70+
71+
return new runtime.JSONApiResponse(response, (jsonValue) =>
72+
DeleteFilesResponseFromJSON(jsonValue)
73+
);
74+
}
75+
76+
/**
77+
* Delete files from a bucket
78+
*/
79+
async fileDeleteControllerDeleteFiles(
80+
requestParameters: FileDeleteControllerDeleteFilesRequest,
81+
initOverrides?: RequestInit | runtime.InitOverrideFunction
82+
): Promise<DeleteFilesResponse> {
83+
const response = await this.fileDeleteControllerDeleteFilesRaw(
84+
requestParameters,
85+
initOverrides
86+
);
87+
return await response.value();
88+
}
89+
}

‎src/internal/apis/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from './AuthApi';
66
export * from './EmailApi';
77
export * from './FileBucketApi';
88
export * from './FileConfigApi';
9+
export * from './FileDeleteApi';
910
export * from './FileDownloadApi';
1011
export * from './FileProviderApi';
1112
export * from './FileUploadApi';
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* Juno
5+
* Juno Public API Docs
6+
*
7+
* The version of the OpenAPI document: 1.0
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
import { mapValues } from '../runtime';
16+
/**
17+
*
18+
* @export
19+
* @interface DeleteFilesModel
20+
*/
21+
export interface DeleteFilesModel {
22+
/**
23+
* Name of the bucket containing the files
24+
* @type {string}
25+
* @memberof DeleteFilesModel
26+
*/
27+
bucketName: string;
28+
/**
29+
* Configuration ID for the bucket
30+
* @type {number}
31+
* @memberof DeleteFilesModel
32+
*/
33+
configId: number;
34+
/**
35+
* List of file names to delete
36+
* @type {Array<string>}
37+
* @memberof DeleteFilesModel
38+
*/
39+
fileNames: Array<string>;
40+
}
41+
42+
/**
43+
* Check if a given object implements the DeleteFilesModel interface.
44+
*/
45+
export function instanceOfDeleteFilesModel(
46+
value: object
47+
): value is DeleteFilesModel {
48+
if (!('bucketName' in value) || value['bucketName'] === undefined)
49+
return false;
50+
if (!('configId' in value) || value['configId'] === undefined) return false;
51+
if (!('fileNames' in value) || value['fileNames'] === undefined) return false;
52+
return true;
53+
}
54+
55+
export function DeleteFilesModelFromJSON(json: any): DeleteFilesModel {
56+
return DeleteFilesModelFromJSONTyped(json, false);
57+
}
58+
59+
export function DeleteFilesModelFromJSONTyped(
60+
json: any,
61+
ignoreDiscriminator: boolean
62+
): DeleteFilesModel {
63+
if (json == null) {
64+
return json;
65+
}
66+
return {
67+
bucketName: json['bucketName'],
68+
configId: json['configId'],
69+
fileNames: json['fileNames'],
70+
};
71+
}
72+
73+
export function DeleteFilesModelToJSON(
74+
value?: DeleteFilesModel | null
75+
): any {
76+
if (value == null) {
77+
return value;
78+
}
79+
return {
80+
bucketName: value['bucketName'],
81+
configId: value['configId'],
82+
fileNames: value['fileNames'],
83+
};
84+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* Juno
5+
* Juno Public API Docs
6+
*
7+
* The version of the OpenAPI document: 1.0
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
import { mapValues } from '../runtime';
16+
/**
17+
*
18+
* @export
19+
* @interface DeleteFilesResponse
20+
*/
21+
export interface DeleteFilesResponse {
22+
/**
23+
* The name of the bucket from which files were deleted
24+
* @type {string}
25+
* @memberof DeleteFilesResponse
26+
*/
27+
bucketName: string;
28+
/**
29+
* List of file names that were deleted
30+
* @type {Array<string>}
31+
* @memberof DeleteFilesResponse
32+
*/
33+
fileNames: Array<string>;
34+
}
35+
36+
/**
37+
* Check if a given object implements the DeleteFilesResponse interface.
38+
*/
39+
export function instanceOfDeleteFilesResponse(
40+
value: object
41+
): value is DeleteFilesResponse {
42+
if (!('bucketName' in value) || value['bucketName'] === undefined)
43+
return false;
44+
if (!('fileNames' in value) || value['fileNames'] === undefined) return false;
45+
return true;
46+
}
47+
48+
export function DeleteFilesResponseFromJSON(json: any): DeleteFilesResponse {
49+
return DeleteFilesResponseFromJSONTyped(json, false);
50+
}
51+
52+
export function DeleteFilesResponseFromJSONTyped(
53+
json: any,
54+
ignoreDiscriminator: boolean
55+
): DeleteFilesResponse {
56+
if (json == null) {
57+
return json;
58+
}
59+
return {
60+
bucketName: json['bucketName'],
61+
fileNames: json['fileNames'],
62+
};
63+
}
64+
65+
export function DeleteFilesResponseToJSON(
66+
value?: DeleteFilesResponse | null
67+
): any {
68+
if (value == null) {
69+
return value;
70+
}
71+
return {
72+
bucketName: value['bucketName'],
73+
fileNames: value['fileNames'],
74+
};
75+
}

‎src/internal/models/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export * from './CustomEventTypeResponse';
1313
export * from './CustomGraphType';
1414
export * from './CustomGraphTypeResponse';
1515
export * from './DeleteFileBucketModel';
16+
export * from './DeleteFilesModel';
17+
export * from './DeleteFilesResponse';
1618
export * from './DownloadFileModel';
1719
export * from './DownloadFileResponse';
1820
export * from './EmailConfigResponse';

‎src/lib/file.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import {
22
Configuration,
33
DeleteFileBucketModel,
4+
DeleteFilesModel,
5+
DeleteFilesResponse,
46
DownloadFileModel,
57
DownloadFileResponse,
68
FileBucket,
79
FileBucketApi,
810
FileConfigApi,
911
FileConfigResponse,
12+
FileDeleteApi,
1013
FileDownloadApi,
1114
FileProvider,
1215
FileProviderApi,
@@ -26,6 +29,7 @@ export class FileAPI {
2629
private configApi: FileConfigApi;
2730
private uploadApi: FileUploadApi;
2831
private downloadApi: FileDownloadApi;
32+
private deleteApi: FileDeleteApi;
2933
private bucketApi: FileBucketApi;
3034
private providerApi: FileProviderApi;
3135

@@ -37,6 +41,7 @@ export class FileAPI {
3741
this.configApi = new FileConfigApi(config);
3842
this.uploadApi = new FileUploadApi(config);
3943
this.downloadApi = new FileDownloadApi(config);
44+
this.deleteApi = new FileDeleteApi(config);
4045
this.bucketApi = new FileBucketApi(config);
4146
this.providerApi = new FileProviderApi(config);
4247
}
@@ -295,6 +300,46 @@ export class FileAPI {
295300
});
296301
}
297302

303+
async deleteFiles(
304+
options: {
305+
bucketName: string;
306+
configId: number;
307+
fileNames: string[];
308+
},
309+
credentials?: ApiCredentials
310+
): Promise<DeleteFilesResponse> {
311+
const { bucketName, configId, fileNames } = options;
312+
313+
validateString(bucketName, 'bucketName must be non-empty');
314+
if (typeof configId !== 'number') {
315+
throw new JunoValidationError('configId must be a number');
316+
}
317+
if (!Array.isArray(fileNames) || fileNames.length === 0) {
318+
throw new JunoValidationError('fileNames must be a non-empty array');
319+
}
320+
321+
const headers: Record<string, string> = {};
322+
if (credentials?.userJwt) {
323+
headers['X-User-JWT'] = credentials.userJwt;
324+
}
325+
if (credentials?.projectId !== undefined) {
326+
headers['X-Project-Id'] = String(credentials.projectId);
327+
}
328+
329+
const model: DeleteFilesModel = {
330+
bucketName,
331+
configId,
332+
fileNames,
333+
};
334+
335+
return await this.deleteApi.fileDeleteControllerDeleteFiles(
336+
{ deleteFilesModel: model },
337+
async ({ init }) => ({
338+
headers: { ...(init.headers as Record<string, string>), ...headers },
339+
})
340+
);
341+
}
342+
298343
async downloadFile(options: {
299344
bucketName: string;
300345
configId: number;

0 commit comments

Comments
 (0)