mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-01-17 14:31:21 -05:00
Upload component (#108)
* unified upload button + download backups * javascript toolings * fix vuetur config * fixed type check error * refactor: clean up bag javascript Co-authored-by: Hayden <hay-kot@pm.me>
This commit is contained in:
@@ -16,8 +16,8 @@ function processResponse(response) {
|
||||
}
|
||||
|
||||
const apiReq = {
|
||||
post: async function(url, data) {
|
||||
let response = await axios.post(url, data).catch(function(error) {
|
||||
post: async function (url, data) {
|
||||
let response = await axios.post(url, data).catch(function (error) {
|
||||
if (error.response) {
|
||||
processResponse(error.response);
|
||||
return error.response;
|
||||
@@ -27,8 +27,8 @@ const apiReq = {
|
||||
return response;
|
||||
},
|
||||
|
||||
get: async function(url, data) {
|
||||
let response = await axios.get(url, data).catch(function(error) {
|
||||
get: async function (url, data) {
|
||||
let response = await axios.get(url, data).catch(function (error) {
|
||||
if (error.response) {
|
||||
processResponse(error.response);
|
||||
return response;
|
||||
@@ -38,8 +38,8 @@ const apiReq = {
|
||||
return response;
|
||||
},
|
||||
|
||||
delete: async function(url, data) {
|
||||
let response = await axios.delete(url, data).catch(function(error) {
|
||||
delete: async function (url, data) {
|
||||
let response = await axios.delete(url, data).catch(function (error) {
|
||||
if (error.response) {
|
||||
processResponse(error.response);
|
||||
return response;
|
||||
|
||||
@@ -10,6 +10,7 @@ const backupURLs = {
|
||||
createBackup: `${backupBase}export/database/`,
|
||||
importBackup: (fileName) => `${backupBase}${fileName}/import/`,
|
||||
deleteBackup: (fileName) => `${backupBase}${fileName}/delete/`,
|
||||
downloadBackup: (fileName) => `${backupBase}${fileName}/download/`,
|
||||
};
|
||||
|
||||
export default {
|
||||
@@ -32,4 +33,8 @@ export default {
|
||||
let response = apiReq.post(backupURLs.createBackup, data);
|
||||
return response;
|
||||
},
|
||||
async download(fileName) {
|
||||
let response = await apiReq.get(backupURLs.downloadBackup(fileName));
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
13
frontend/src/api/upload.js
Normal file
13
frontend/src/api/upload.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { apiReq } from "./api-utils";
|
||||
|
||||
export default {
|
||||
// import api from "../api";
|
||||
async uploadFile(url, fileObject) {
|
||||
let response = await apiReq.post(url, fileObject, {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user