|
@@ -1,6 +1,6 @@
|
|
|
import axios from "axios";
|
|
|
import { apiUrl } from "@/env";
|
|
|
-import type { IUserProfile, IUserProfileUpdate, IUserProfileCreate, Video, VideoCreate} from "@/interfaces";
|
|
|
+import type { IUserProfile, IUserProfileUpdate, IUserProfileCreate, Video, VideoCreate, ArticleCreate, ImageDownload } from "@/interfaces";
|
|
|
|
|
|
function authHeaders(token: string) {
|
|
|
return {
|
|
@@ -49,21 +49,56 @@ export const api = {
|
|
|
async registerUser(data: IUserProfileCreate) {
|
|
|
return axios.post(`${apiUrl}/api/v1/users/open`, data);
|
|
|
},
|
|
|
- async testCeleryMsg(token: string, data:{msg: string}){
|
|
|
- return axios.post<{msg:string}>(`${apiUrl}/api/v1/utils/test-celery/msg`, data, authHeaders(token));
|
|
|
+ async testCeleryMsg(token: string, data: { msg: string }) {
|
|
|
+ return axios.post<{ msg: string }>(`${apiUrl}/api/v1/utils/test-celery/msg`, data, authHeaders(token));
|
|
|
},
|
|
|
- async testCeleryFile(token: string, file: File){
|
|
|
+ async testCeleryFile(token: string, file: File) {
|
|
|
const formData = new FormData();
|
|
|
formData.append("file", file)
|
|
|
- return axios.post<{msg:string}>(`${apiUrl}/api/v1/utils/test-celery/file`, formData, authHeaders(token));
|
|
|
+ return axios.post<{ msg: string }>(`${apiUrl}/api/v1/utils/test-celery/file`, formData, authHeaders(token));
|
|
|
},
|
|
|
- async uploadPlot(token: string, video_data:VideoCreate, file: File){
|
|
|
+ async uploadPlot(token: string, video_data: VideoCreate, file: File) {
|
|
|
const formData = new FormData();
|
|
|
formData.append("title", video_data.title)
|
|
|
formData.append("anchor_id", video_data.anchor_id.toString())
|
|
|
formData.append("lang_id", video_data.lang_id.toString())
|
|
|
formData.append("upload_file", file)
|
|
|
- return axios.post<{msg:string}>(`${apiUrl}/api/v1/videos/`, formData, authHeaders(token));
|
|
|
+ return axios.post<{ msg: string }>(`${apiUrl}/api/v1/videos/`, formData, authHeaders(token));
|
|
|
+ },
|
|
|
+ async uploadImage(token: string, file: File[]) {
|
|
|
+ const formData = new FormData();
|
|
|
+ for (let i = 0; i < file.length; i++) {
|
|
|
+ const element = file[i];
|
|
|
+ formData.append("upload_files", element);
|
|
|
+ }
|
|
|
+ return axios.post<{ filenames: string[] }>(`${apiUrl}/api/v1/images/sr`, formData, authHeaders(token));
|
|
|
+ },
|
|
|
+ async getImage(token: string, data: ImageDownload) {
|
|
|
+ axios({
|
|
|
+ url: `${apiUrl}/api/v1/images/sr?stored_file_name=${data.stored_file_name}&file_name=${data.file_name}`,
|
|
|
+ method: 'GET',
|
|
|
+ responseType: 'blob',
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${token}`
|
|
|
+ },
|
|
|
+ }).then((response) => {
|
|
|
+ console.log('getImage response', response);
|
|
|
+ const href = URL.createObjectURL(response.data);
|
|
|
+ const link = document.createElement('a');
|
|
|
+ link.href = href;
|
|
|
+ link.setAttribute('download', `${data.stored_file_name}_hr.png`); //or any other extension
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link);
|
|
|
+ URL.revokeObjectURL(href);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ async uploadArticle(token: string, article_data: ArticleCreate) {
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append("title", article_data.title)
|
|
|
+ formData.append("link", article_data.link)
|
|
|
+ formData.append("content", article_data.content)
|
|
|
+ return axios.post<{ msg: string }>(`${apiUrl}/api/v1/reputations/`, formData, authHeaders(token));
|
|
|
},
|
|
|
async getVideos(token: string) {
|
|
|
return axios.get<Video[]>(`${apiUrl}/api/v1/videos/`, authHeaders(token));
|
|
@@ -74,5 +109,4 @@ export const api = {
|
|
|
params.append("password", password);
|
|
|
|
|
|
return axios.post(`${apiUrl}/api/v1/login/google/access-token`, params);
|
|
|
- },
|
|
|
};
|