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.

59 lines
1.4 KiB

  1. import axios from 'axios';
  2. export default class ApiService {
  3. private readonly baseUrl: string = 'http://core.sandd';
  4. private readonly apiRoutes = {
  5. file: '/api/file',
  6. searchAndDisplace: '/search-and-displace'
  7. };
  8. constructor()
  9. {}
  10. /**
  11. * Upload a file to the server and return its response.
  12. * Throws an error if the response wasn't successful
  13. *
  14. * @param file
  15. * @returns
  16. */
  17. public async uploadFile(file: File)
  18. {
  19. let formData = new FormData();
  20. formData.append('file', file);
  21. try {
  22. let response = await axios.post(
  23. this.baseUrl + this.apiRoutes.file,
  24. formData,
  25. {
  26. headers: {
  27. 'Content-Type': 'multipart/form-data'
  28. }
  29. }
  30. )
  31. return response.data;
  32. } catch (err) {
  33. throw err;
  34. }
  35. }
  36. /**
  37. * Get data for a file from the server.
  38. * Throws an error if the response wasn't successful
  39. *
  40. * @param fileId
  41. * @returns
  42. */
  43. public async getFileData(fileId: string)
  44. {
  45. try {
  46. let response = await axios.get(this.baseUrl + this.apiRoutes.searchAndDisplace + `/${fileId}`);
  47. return response.data;
  48. } catch (err) {
  49. throw err;
  50. }
  51. }
  52. }