mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
77c1b90e6b
* feat: default project cover images tab * chore: remove unnecessary env vars from turbo.json
101 lines
2.6 KiB
TypeScript
101 lines
2.6 KiB
TypeScript
// services
|
|
import APIService from "services/api.service";
|
|
import { API_BASE_URL } from "helpers/common.helper";
|
|
|
|
interface UnSplashImage {
|
|
id: string;
|
|
created_at: Date;
|
|
updated_at: Date;
|
|
promoted_at: Date;
|
|
width: number;
|
|
height: number;
|
|
color: string;
|
|
blur_hash: string;
|
|
description: null;
|
|
alt_description: string;
|
|
urls: UnSplashImageUrls;
|
|
[key: string]: any;
|
|
}
|
|
|
|
interface UnSplashImageUrls {
|
|
raw: string;
|
|
full: string;
|
|
regular: string;
|
|
small: string;
|
|
thumb: string;
|
|
small_s3: string;
|
|
}
|
|
|
|
class FileServices extends APIService {
|
|
constructor() {
|
|
super(API_BASE_URL);
|
|
}
|
|
|
|
async uploadFile(workspaceSlug: string, file: FormData): Promise<any> {
|
|
return this.mediaUpload(`/api/workspaces/${workspaceSlug}/file-assets/`, file)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async deleteImage(assetUrlWithWorkspaceId: string): Promise<any> {
|
|
return this.delete(`/api/workspaces/file-assets/${assetUrlWithWorkspaceId}/`)
|
|
.then((response) => response?.status)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async deleteFile(workspaceId: string, assetUrl: string): Promise<any> {
|
|
const lastIndex = assetUrl.lastIndexOf("/");
|
|
const assetId = assetUrl.substring(lastIndex + 1);
|
|
|
|
return this.delete(`/api/workspaces/file-assets/${workspaceId}/${assetId}/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
async uploadUserFile(file: FormData): Promise<any> {
|
|
return this.mediaUpload(`/api/users/file-assets/`, file)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async deleteUserFile(assetUrl: string): Promise<any> {
|
|
const lastIndex = assetUrl.lastIndexOf("/");
|
|
const assetId = assetUrl.substring(lastIndex + 1);
|
|
|
|
return this.delete(`/api/users/file-assets/${assetId}`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async getUnsplashImages(query?: string): Promise<UnSplashImage[]> {
|
|
return this.get(`/api/unsplash/`, {
|
|
params: {
|
|
query,
|
|
},
|
|
})
|
|
.then((res) => res?.data?.results ?? res?.data)
|
|
.catch((err) => {
|
|
throw err?.response?.data;
|
|
});
|
|
}
|
|
|
|
async getProjectCoverImages(): Promise<string[]> {
|
|
return this.get(`/api/project-covers/`)
|
|
.then((res) => res?.data)
|
|
.catch((err) => {
|
|
throw err?.response?.data;
|
|
});
|
|
}
|
|
}
|
|
|
|
export default new FileServices();
|