Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

60 lines
1.4 KiB

import axios from 'axios';
export default class ApiService {
private readonly baseUrl: string = 'http://core.sandd';
private readonly apiRoutes = {
file: '/api/file',
searchAndDisplace: '/search-and-displace'
};
constructor()
{}
/**
* Upload a file to the server and return its response.
* Throws an error if the response wasn't successful
*
* @param file
* @returns
*/
public async uploadFile(file: File)
{
let formData = new FormData();
formData.append('file', file);
try {
let response = await axios.post(
this.baseUrl + this.apiRoutes.file,
formData,
{
headers: {
'Content-Type': 'multipart/form-data'
}
}
)
return response.data;
} catch (err) {
throw err;
}
}
/**
* Get data for a file from the server.
* Throws an error if the response wasn't successful
*
* @param fileId
* @returns
*/
public async getFileData(fileId: string)
{
try {
let response = await axios.get(this.baseUrl + this.apiRoutes.searchAndDisplace + `/${fileId}`);
return response.data;
} catch (err) {
throw err;
}
}
}