diff --git a/.editorconfig b/.editorconfig index b7a4a38488..2a106c13b0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,8 +10,6 @@ indent_size = 4 # CA1305 requires using a FormatProvider with int.Parse and string.Format. dotnet_diagnostic.CA1305.severity = none dotnet_diagnostic.CA1710.severity = warning -# CA1825 doesn't like `Produces("application/json")` in our controllers. -dotnet_diagnostic.CA1825.severity = none # TODO: Implement LoggerMessage pattern to remove the CA1848 exception. dotnet_diagnostic.CA1848.severity = none # CS1591 is our only exception to EnforceCodeStyleInBuild+GenerateDocumentationFile. diff --git a/Backend.Tests/Controllers/AudioControllerTests.cs b/Backend.Tests/Controllers/AudioControllerTests.cs index 3aca57c461..b2747eba49 100644 --- a/Backend.Tests/Controllers/AudioControllerTests.cs +++ b/Backend.Tests/Controllers/AudioControllerTests.cs @@ -37,7 +37,7 @@ protected virtual void Dispose(bool disposing) private string _wordId = null!; private const string FileName = "sound.mp3"; // file in Backend.Tests/Assets/ private readonly Stream _stream = File.OpenRead(Path.Combine(Util.AssetsDir, FileName)); - private FileUpload _fileUpload = null!; + private FormFile _file = null!; [SetUp] public void Setup() @@ -51,44 +51,43 @@ public void Setup() _projId = _projRepo.Create(new Project { Name = "AudioControllerTests" }).Result!.Id; _wordId = _wordRepo.Create(Util.RandomWord(_projId)).Result.Id; - var formFile = new FormFile(_stream, 0, _stream.Length, "Name", FileName); - _fileUpload = new FileUpload { File = formFile, Name = "FileName" }; + _file = new FormFile(_stream, 0, _stream.Length, "Name", FileName); } [Test] public void TestUploadAudioFileUnauthorized() { _audioController.ControllerContext.HttpContext = PermissionServiceMock.UnauthorizedHttpContext(); - var result = _audioController.UploadAudioFile(_projId, _wordId, _fileUpload).Result; + var result = _audioController.UploadAudioFile(_projId, _wordId, _file).Result; Assert.That(result, Is.InstanceOf()); - result = _audioController.UploadAudioFile(_projId, _wordId, "", _fileUpload).Result; + result = _audioController.UploadAudioFile(_projId, _wordId, "", _file).Result; Assert.That(result, Is.InstanceOf()); } [Test] public void TestUploadAudioFileInvalidArguments() { - var result = _audioController.UploadAudioFile("invalid/projId", _wordId, _fileUpload).Result; + var result = _audioController.UploadAudioFile("invalid/projId", _wordId, _file).Result; Assert.That(result, Is.TypeOf()); - result = _audioController.UploadAudioFile(_projId, "invalid/wordId", _fileUpload).Result; + result = _audioController.UploadAudioFile(_projId, "invalid/wordId", _file).Result; Assert.That(result, Is.TypeOf()); - result = _audioController.UploadAudioFile("invalid/projId", _wordId, "speakerId", _fileUpload).Result; + result = _audioController.UploadAudioFile("invalid/projId", _wordId, "speakerId", _file).Result; Assert.That(result, Is.TypeOf()); - result = _audioController.UploadAudioFile(_projId, "invalid/wordId", "speakerId", _fileUpload).Result; + result = _audioController.UploadAudioFile(_projId, "invalid/wordId", "speakerId", _file).Result; Assert.That(result, Is.TypeOf()); } [Test] public void TestUploadConsentNullFile() { - var result = _audioController.UploadAudioFile(_projId, _wordId, new()).Result; + var result = _audioController.UploadAudioFile(_projId, _wordId, null).Result; Assert.That(result, Is.InstanceOf()); - result = _audioController.UploadAudioFile(_projId, _wordId, "speakerId", new()).Result; + result = _audioController.UploadAudioFile(_projId, _wordId, "speakerId", null).Result; Assert.That(result, Is.InstanceOf()); } @@ -96,20 +95,18 @@ public void TestUploadConsentNullFile() public void TestUploadConsentEmptyFile() { // Use 0 for the third argument - var formFile = new FormFile(_stream, 0, 0, "Name", FileName); - _fileUpload = new FileUpload { File = formFile, Name = FileName }; + _file = new FormFile(_stream, 0, 0, "Name", FileName); - var result = _audioController.UploadAudioFile(_projId, _wordId, _fileUpload).Result; + var result = _audioController.UploadAudioFile(_projId, _wordId, _file).Result; Assert.That(result, Is.InstanceOf()); - result = _audioController.UploadAudioFile(_projId, _wordId, "speakerId", _fileUpload).Result; + result = _audioController.UploadAudioFile(_projId, _wordId, "speakerId", _file).Result; Assert.That(result, Is.InstanceOf()); } [Test] public void TestUploadAudioFile() { - // `_fileUpload` contains the file stream and the name of the file. - _ = _audioController.UploadAudioFile(_projId, _wordId, "speakerId", _fileUpload).Result; + _ = _audioController.UploadAudioFile(_projId, _wordId, "speakerId", _file).Result; var foundWord = _wordRepo.GetWord(_projId, _wordId).Result; Assert.That(foundWord?.Audio, Is.Not.Null); diff --git a/Backend.Tests/Controllers/AvatarControllerTests.cs b/Backend.Tests/Controllers/AvatarControllerTests.cs index 83e4682a67..244253c48e 100644 --- a/Backend.Tests/Controllers/AvatarControllerTests.cs +++ b/Backend.Tests/Controllers/AvatarControllerTests.cs @@ -64,14 +64,12 @@ private static void DeleteAvatarFile(string userId) [Test] public void TestAvatarImport() { - const string fileName = "combine.png"; + const string fileName = "combine.png"; // file in Backend.Tests/Assets/ var filePath = Path.Combine(Util.AssetsDir, fileName); using var stream = File.OpenRead(filePath); + var file = new FormFile(stream, 0, stream.Length, "dave", fileName); - var formFile = new FormFile(stream, 0, stream.Length, "dave", fileName); - var fileUpload = new FileUpload { File = formFile, Name = "FileName" }; - - _ = _avatarController.UploadAvatar(_jwtAuthenticatedUser.Id, fileUpload).Result; + _ = _avatarController.UploadAvatar(_jwtAuthenticatedUser.Id, file).Result; var foundUser = _userRepo.GetUser(_jwtAuthenticatedUser.Id).Result; Assert.That(foundUser?.Avatar, Is.Not.Null); diff --git a/Backend.Tests/Controllers/LiftControllerTests.cs b/Backend.Tests/Controllers/LiftControllerTests.cs index 28baa591da..b3b0ffb596 100644 --- a/Backend.Tests/Controllers/LiftControllerTests.cs +++ b/Backend.Tests/Controllers/LiftControllerTests.cs @@ -31,6 +31,10 @@ public class LiftControllerTests : IDisposable private IWordService _wordService = null!; private LiftController _liftController = null!; + private const string FileName = "SingleEntryLiftWithSound.zip"; // file in Backend.Tests/Assets/ + private readonly Stream _stream = File.OpenRead(Path.Combine(Util.AssetsDir, FileName)); + private FormFile _file = null!; + public void Dispose() { Dispose(true); @@ -66,6 +70,7 @@ public void Setup() _logger = new MockLogger(); _projId = _projRepo.Create(new Project { Name = ProjName }).Result!.Id; + _file = new FormFile(_stream, 0, _stream.Length, "Name", FileName); } [TearDown] @@ -144,12 +149,9 @@ public static string RandomLiftFile(string path) return name; } - private static FileUpload InitFile(Stream stream, string filename) + private static FormFile InitFile(Stream stream, string filename) { - var formFile = new FormFile(stream, 0, stream.Length, "name", filename); - var fileUpload = new FileUpload { File = formFile, Name = "FileName" }; - - return fileUpload; + return new(stream, 0, stream.Length, "name", filename); } /// Extract the binary contents of a zip file to a temporary directory. @@ -233,14 +235,14 @@ private static async Task DownloadAndReadLift(LiftController liftControl public void TestUploadLiftFileNoPermission() { _liftController.ControllerContext.HttpContext = PermissionServiceMock.UnauthorizedHttpContext(); - var result = _liftController.UploadLiftFile(_projId, new FileUpload()).Result; + var result = _liftController.UploadLiftFile(_projId, _file).Result; Assert.That(result, Is.InstanceOf()); } [Test] public void TestUploadLiftFileInvalidProjectId() { - var result = _liftController.UploadLiftFile("../hack", new FileUpload()).Result; + var result = _liftController.UploadLiftFile("../hack", _file).Result; Assert.That(result, Is.InstanceOf()); } @@ -248,7 +250,7 @@ public void TestUploadLiftFileInvalidProjectId() public void TestUploadLiftFileAlreadyImported() { var projId = _projRepo.Create(new Project { Name = "already has import", LiftImported = true }).Result!.Id; - var result = _liftController.UploadLiftFile(projId, new FileUpload()).Result; + var result = _liftController.UploadLiftFile(projId, _file).Result; Assert.That(result, Is.InstanceOf()); Assert.That(((BadRequestObjectResult)result).Value, Contains.Substring("LIFT")); } @@ -256,7 +258,7 @@ public void TestUploadLiftFileAlreadyImported() [Test] public void TestUploadLiftFileBadFile() { - var result = _liftController.UploadLiftFile(_projId, new FileUpload()).Result; + var result = _liftController.UploadLiftFile(_projId, null).Result; Assert.That(result, Is.InstanceOf()); Assert.That(((BadRequestObjectResult)result).Value, Is.InstanceOf()); } diff --git a/Backend.Tests/Controllers/SpeakerControllerTests.cs b/Backend.Tests/Controllers/SpeakerControllerTests.cs index 3086010e96..7d82a5e2e7 100644 --- a/Backend.Tests/Controllers/SpeakerControllerTests.cs +++ b/Backend.Tests/Controllers/SpeakerControllerTests.cs @@ -36,8 +36,7 @@ protected virtual void Dispose(bool disposing) private const string FileName = "sound.mp3"; // file in Backend.Tests/Assets/ private Speaker _speaker = null!; private readonly Stream _stream = File.OpenRead(Path.Combine(Util.AssetsDir, FileName)); - private FormFile _formFile = null!; - private FileUpload _fileUpload = null!; + private FormFile _file = null!; [SetUp] public void Setup() @@ -48,12 +47,11 @@ public void Setup() _speaker = _speakerRepo.Create(new Speaker { Name = Name, ProjectId = ProjId }).Result; - _formFile = new FormFile(_stream, 0, _stream.Length, "name", FileName) + _file = new FormFile(_stream, 0, _stream.Length, "name", FileName) { Headers = new HeaderDictionary(), ContentType = "audio" }; - _fileUpload = new FileUpload { File = _formFile, Name = FileName }; } [Test] @@ -258,10 +256,10 @@ public void TestUpdateSpeakerNameNewName() [Test] public void TestUploadConsentInvalidArguments() { - var result = _speakerController.UploadConsent("invalid/projectId", _speaker.Id, _fileUpload).Result; + var result = _speakerController.UploadConsent("invalid/projectId", _speaker.Id, _file).Result; Assert.That(result, Is.InstanceOf()); - result = _speakerController.UploadConsent(ProjId, "invalid/speakerId", _fileUpload).Result; + result = _speakerController.UploadConsent(ProjId, "invalid/speakerId", _file).Result; Assert.That(result, Is.InstanceOf()); } @@ -269,21 +267,21 @@ public void TestUploadConsentInvalidArguments() public void TestUploadConsentUnauthorized() { _speakerController.ControllerContext.HttpContext = PermissionServiceMock.UnauthorizedHttpContext(); - var result = _speakerController.UploadConsent(ProjId, _speaker.Id, _fileUpload).Result; + var result = _speakerController.UploadConsent(ProjId, _speaker.Id, _file).Result; Assert.That(result, Is.InstanceOf()); } [Test] public void TestUploadConsentNoSpeaker() { - var result = _speakerController.UploadConsent(ProjId, "other", _fileUpload).Result; + var result = _speakerController.UploadConsent(ProjId, "other", _file).Result; Assert.That(result, Is.InstanceOf()); } [Test] public void TestUploadConsentNullFile() { - var result = _speakerController.UploadConsent(ProjId, _speaker.Id, new()).Result; + var result = _speakerController.UploadConsent(ProjId, _speaker.Id, null).Result; Assert.That(result, Is.InstanceOf()); } @@ -291,31 +289,28 @@ public void TestUploadConsentNullFile() public void TestUploadConsentEmptyFile() { // Use 0 for the third argument - _formFile = new FormFile(_stream, 0, 0, "name", FileName) + _file = new FormFile(_stream, 0, 0, "name", FileName) { Headers = new HeaderDictionary(), ContentType = "audio" }; - _fileUpload = new FileUpload { File = _formFile, Name = FileName }; - var result = _speakerController.UploadConsent(ProjId, _speaker.Id, _fileUpload).Result; + var result = _speakerController.UploadConsent(ProjId, _speaker.Id, _file).Result; Assert.That(result, Is.InstanceOf()); } [Test] public void TestUploadConsentInvalidContentType() { - _formFile.ContentType = "neither audi0 nor 1mage"; - _fileUpload = new FileUpload { File = _formFile, Name = FileName }; - var result = _speakerController.UploadConsent(ProjId, _speaker.Id, _fileUpload).Result; + _file.ContentType = "neither audi0 nor 1mage"; + var result = _speakerController.UploadConsent(ProjId, _speaker.Id, _file).Result; Assert.That(result, Is.InstanceOf()); } [Test] public void TestUploadConsentAddAudioConsent() { - _formFile.ContentType = "audio/something"; - _fileUpload = new FileUpload { File = _formFile, Name = FileName }; - var result = _speakerController.UploadConsent(ProjId, _speaker.Id, _fileUpload).Result; + _file.ContentType = "audio/something"; + var result = _speakerController.UploadConsent(ProjId, _speaker.Id, _file).Result; Assert.That(result, Is.InstanceOf()); var value = (Speaker)((ObjectResult)result).Value!; Assert.That(value.Consent, Is.EqualTo(ConsentType.Audio)); @@ -326,9 +321,8 @@ public void TestUploadConsentAddAudioConsent() [Test] public void TestUploadConsentAddImageConsent() { - _formFile.ContentType = "image/anything"; - _fileUpload = new FileUpload { File = _formFile, Name = FileName }; - var result = _speakerController.UploadConsent(ProjId, _speaker.Id, _fileUpload).Result; + _file.ContentType = "image/anything"; + var result = _speakerController.UploadConsent(ProjId, _speaker.Id, _file).Result; Assert.That(result, Is.InstanceOf()); var value = (Speaker)((ObjectResult)result).Value!; Assert.That(value.Consent, Is.EqualTo(ConsentType.Image)); diff --git a/Backend/Controllers/AudioController.cs b/Backend/Controllers/AudioController.cs index da8efecf33..763d7f329c 100644 --- a/Backend/Controllers/AudioController.cs +++ b/Backend/Controllers/AudioController.cs @@ -61,28 +61,27 @@ public IActionResult DownloadAudioFile(string projectId, string wordId, string f } /// - /// Adds a pronunciation to a specified project word + /// Adds a pronunciation to a specified project word /// and saves locally to ~/.CombineFiles/{ProjectId}/Import/ExtractedLocation/Lift/audio /// /// Id of updated word [HttpPost("upload", Name = "UploadAudioFile")] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(string))] - public async Task UploadAudioFile(string projectId, string wordId, - [FromForm] FileUpload fileUpload) + public async Task UploadAudioFile(string projectId, string wordId, IFormFile? file) { - return await UploadAudioFile(projectId, wordId, "", fileUpload); + return await UploadAudioFile(projectId, wordId, "", file); } /// - /// Adds a pronunciation with a specified speaker to a project word + /// Adds a pronunciation with a specified speaker to a project word /// and saves locally to ~/.CombineFiles/{ProjectId}/Import/ExtractedLocation/Lift/audio /// /// Id of updated word [HttpPost("upload/{speakerId}", Name = "UploadAudioFileWithSpeaker")] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(string))] - public async Task UploadAudioFile(string projectId, string wordId, string speakerId, - [FromForm] FileUpload fileUpload) + public async Task UploadAudioFile( + string projectId, string wordId, string speakerId, IFormFile? file) { if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry, projectId)) { @@ -101,7 +100,6 @@ public async Task UploadAudioFile(string projectId, string wordId return new UnsupportedMediaTypeResult(); } - var file = fileUpload.File; if (file is null) { return BadRequest("Null File"); @@ -115,10 +113,10 @@ public async Task UploadAudioFile(string projectId, string wordId // This path should be unique even though it is only based on the Word ID because currently, a new // Word is created each time an audio file is uploaded. - fileUpload.FilePath = FileStorage.GenerateAudioFilePathForWord(projectId, wordId); + var filePath = FileStorage.GenerateAudioFilePathForWord(projectId, wordId); // Copy the file data to a new local file - await using (var fs = new FileStream(fileUpload.FilePath, FileMode.Create)) + await using (var fs = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(fs); } @@ -129,7 +127,7 @@ public async Task UploadAudioFile(string projectId, string wordId { return NotFound(wordId); } - var audio = new Pronunciation(Path.GetFileName(fileUpload.FilePath), speakerId); + var audio = new Pronunciation(Path.GetFileName(filePath), speakerId); word.Audio.Add(audio); // Update the word with new audio file diff --git a/Backend/Controllers/AvatarController.cs b/Backend/Controllers/AvatarController.cs index 7787d62b0d..a3d77d36eb 100644 --- a/Backend/Controllers/AvatarController.cs +++ b/Backend/Controllers/AvatarController.cs @@ -53,14 +53,13 @@ public async Task DownloadAvatar(string userId) /// Path to local avatar file [HttpPost("upload", Name = "UploadAvatar")] [ProducesResponseType(StatusCodes.Status200OK)] - public async Task UploadAvatar(string userId, [FromForm] FileUpload fileUpload) + public async Task UploadAvatar(string userId, IFormFile? file) { if (!_permissionService.IsUserIdAuthorized(HttpContext, userId)) { return Forbid(); } - var file = fileUpload.File; if (file is null) { return BadRequest("Null File"); @@ -80,16 +79,16 @@ public async Task UploadAvatar(string userId, [FromForm] FileUplo } // Generate path to store avatar file. - fileUpload.FilePath = FileStorage.GenerateAvatarFilePath(userId); + var filePath = FileStorage.GenerateAvatarFilePath(userId); // Copy file data to a new local file. - await using (var fs = new FileStream(fileUpload.FilePath, FileMode.OpenOrCreate)) + await using (var fs = new FileStream(filePath, FileMode.OpenOrCreate)) { await file.CopyToAsync(fs); } // Update the user's avatar file. - user.Avatar = fileUpload.FilePath; + user.Avatar = filePath; user.HasAvatar = true; _ = await _userRepo.Update(userId, user); diff --git a/Backend/Controllers/LiftController.cs b/Backend/Controllers/LiftController.cs index d292da9fdf..f9a6401090 100644 --- a/Backend/Controllers/LiftController.cs +++ b/Backend/Controllers/LiftController.cs @@ -53,18 +53,22 @@ public LiftController( // Note: The HTTP Proxy in front, such as NGINX, also needs to be configured // to allow large requests through as well. [RequestSizeLimit(250_000_000)] // 250MB. - public async Task UploadLiftFileAndGetWritingSystems([FromForm] FileUpload fileUpload) + public async Task UploadLiftFileAndGetWritingSystems(IFormFile? file) { var userId = _permissionService.GetUserId(HttpContext); - return await UploadLiftFileAndGetWritingSystems(fileUpload, userId); + if (file is null) + { + return BadRequest("Null File"); + } + return await UploadLiftFileAndGetWritingSystems(file, userId); } - internal async Task UploadLiftFileAndGetWritingSystems(FileUpload fileUpload, string userId) + internal async Task UploadLiftFileAndGetWritingSystems(IFormFile? file, string userId) { string extractedLiftRootPath; try { - var extractDir = await FileOperations.ExtractZipFile(fileUpload.File); + var extractDir = await FileOperations.ExtractZipFile(file); _liftService.StoreImport(userId, extractDir); extractedLiftRootPath = LiftHelper.GetLiftRootFromExtractedZip(extractDir); } @@ -146,7 +150,7 @@ internal async Task FinishUploadLiftFile(string projectId, string // Note: The HTTP Proxy in front, such as NGINX, also needs to be configured // to allow large requests through as well. [RequestSizeLimit(250_000_000)] // 250MB. - public async Task UploadLiftFile(string projectId, [FromForm] FileUpload fileUpload) + public async Task UploadLiftFile(string projectId, IFormFile? file) { if (!await _permissionService.HasProjectPermission(HttpContext, Permission.Import, projectId)) { @@ -173,7 +177,7 @@ public async Task UploadLiftFile(string projectId, [FromForm] Fil string extractedLiftRootPath; try { - extractDir = await FileOperations.ExtractZipFile(fileUpload.File); + extractDir = await FileOperations.ExtractZipFile(file); extractedLiftRootPath = LiftHelper.GetLiftRootFromExtractedZip(extractDir); } catch (Exception e) diff --git a/Backend/Controllers/SpeakerController.cs b/Backend/Controllers/SpeakerController.cs index 06cb2e090a..7eae5b76eb 100644 --- a/Backend/Controllers/SpeakerController.cs +++ b/Backend/Controllers/SpeakerController.cs @@ -233,8 +233,7 @@ public async Task UpdateSpeakerName(string projectId, string spea /// Updated speaker [HttpPost("consent/{speakerId}", Name = "UploadConsent")] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(Speaker))] - public async Task UploadConsent( - string projectId, string speakerId, [FromForm] FileUpload upload) + public async Task UploadConsent(string projectId, string speakerId, IFormFile? file) { // Sanitize user input try @@ -261,7 +260,6 @@ public async Task UploadConsent( } // Ensure file is valid - var file = upload.File; if (file is null) { return BadRequest("Null File"); diff --git a/Backend/Models/Word.cs b/Backend/Models/Word.cs index 3266fbbc68..baece02379 100644 --- a/Backend/Models/Word.cs +++ b/Backend/Models/Word.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using Microsoft.AspNetCore.Http; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; @@ -439,23 +438,4 @@ public void Append(Flag other) Text += $"; {other.Text}"; } } - - /// Helper object that contains a file along with its name and path - public class FileUpload - { - [Required] - public IFormFile? File { get; set; } - [Required] - public string Name { get; set; } - [Required] - public string FilePath { get; set; } - - /// Models by ASP.NET Core POSTs must have a constructor with zero arguments. - public FileUpload() - { - File = null; - Name = ""; - FilePath = ""; - } - } } diff --git a/docs/user_guide/assets/licenses/frontend_licenses.txt b/docs/user_guide/assets/licenses/frontend_licenses.txt index 6f35097e96..efa494cfd7 100644 --- a/docs/user_guide/assets/licenses/frontend_licenses.txt +++ b/docs/user_guide/assets/licenses/frontend_licenses.txt @@ -40637,27 +40637,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -axios 0.27.2 +axios 1.7.2 MIT -Copyright (c) 2014-present Matt Zabriskie +# Copyright (c) 2014-present Matt Zabriskie & Collaborators -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. babel-plugin-macros 3.1.0 @@ -43047,6 +43035,30 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +proxy-from-env 1.1.0 +MIT +The MIT License + +Copyright (C) 2016-2018 Rob Wu + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + psl 1.9.0 MIT The MIT License (MIT) diff --git a/package-lock.json b/package-lock.json index 1235a0ea92..49a8e033f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@redux-devtools/extension": "^3.2.5", "@reduxjs/toolkit": "^1.9.5", "@segment/analytics-next": "^1.55.0", - "axios": "^0.27.2", + "axios": "^1.7.2", "chart.js": "^4.4.0", "crypto-js": "^4.2.0", "dayjs": "^1.11.9", @@ -10162,12 +10162,13 @@ } }, "node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", "dependencies": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, "node_modules/axobject-query": { @@ -22882,6 +22883,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", diff --git a/package.json b/package.json index 3da4f79f70..1406d7fbb1 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@redux-devtools/extension": "^3.2.5", "@reduxjs/toolkit": "^1.9.5", "@segment/analytics-next": "^1.55.0", - "axios": "^0.27.2", + "axios": "^1.7.2", "chart.js": "^4.4.0", "crypto-js": "^4.2.0", "dayjs": "^1.11.9", diff --git a/src/api/api/audio-api.ts b/src/api/api/audio-api.ts index 62e9438bfa..a44c28da10 100644 --- a/src/api/api/audio-api.ts +++ b/src/api/api/audio-api.ts @@ -156,30 +156,20 @@ export const AudioApiAxiosParamCreator = function ( * * @param {string} projectId * @param {string} wordId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ uploadAudioFile: async ( projectId: string, wordId: string, - file: any, - name: string, - filePath: string, + file?: any, options: any = {} ): Promise => { // verify required parameter 'projectId' is not null or undefined assertParamExists("uploadAudioFile", "projectId", projectId); // verify required parameter 'wordId' is not null or undefined assertParamExists("uploadAudioFile", "wordId", wordId); - // verify required parameter 'file' is not null or undefined - assertParamExists("uploadAudioFile", "file", file); - // verify required parameter 'name' is not null or undefined - assertParamExists("uploadAudioFile", "name", name); - // verify required parameter 'filePath' is not null or undefined - assertParamExists("uploadAudioFile", "filePath", filePath); const localVarPath = `/v1/projects/{projectId}/words/{wordId}/audio/upload` .replace(`{${"projectId"}}`, encodeURIComponent(String(projectId))) @@ -203,15 +193,7 @@ export const AudioApiAxiosParamCreator = function ( FormData)(); if (file !== undefined) { - localVarFormParams.append("File", file as any); - } - - if (name !== undefined) { - localVarFormParams.append("Name", name as any); - } - - if (filePath !== undefined) { - localVarFormParams.append("FilePath", filePath as any); + localVarFormParams.append("file", file as any); } localVarHeaderParameter["Content-Type"] = "multipart/form-data"; @@ -236,9 +218,7 @@ export const AudioApiAxiosParamCreator = function ( * @param {string} projectId * @param {string} wordId * @param {string} speakerId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ @@ -246,9 +226,7 @@ export const AudioApiAxiosParamCreator = function ( projectId: string, wordId: string, speakerId: string, - file: any, - name: string, - filePath: string, + file?: any, options: any = {} ): Promise => { // verify required parameter 'projectId' is not null or undefined @@ -257,12 +235,6 @@ export const AudioApiAxiosParamCreator = function ( assertParamExists("uploadAudioFileWithSpeaker", "wordId", wordId); // verify required parameter 'speakerId' is not null or undefined assertParamExists("uploadAudioFileWithSpeaker", "speakerId", speakerId); - // verify required parameter 'file' is not null or undefined - assertParamExists("uploadAudioFileWithSpeaker", "file", file); - // verify required parameter 'name' is not null or undefined - assertParamExists("uploadAudioFileWithSpeaker", "name", name); - // verify required parameter 'filePath' is not null or undefined - assertParamExists("uploadAudioFileWithSpeaker", "filePath", filePath); const localVarPath = `/v1/projects/{projectId}/words/{wordId}/audio/upload/{speakerId}` .replace(`{${"projectId"}}`, encodeURIComponent(String(projectId))) @@ -287,15 +259,7 @@ export const AudioApiAxiosParamCreator = function ( FormData)(); if (file !== undefined) { - localVarFormParams.append("File", file as any); - } - - if (name !== undefined) { - localVarFormParams.append("Name", name as any); - } - - if (filePath !== undefined) { - localVarFormParams.append("FilePath", filePath as any); + localVarFormParams.append("file", file as any); } localVarHeaderParameter["Content-Type"] = "multipart/form-data"; @@ -388,18 +352,14 @@ export const AudioApiFp = function (configuration?: Configuration) { * * @param {string} projectId * @param {string} wordId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ async uploadAudioFile( projectId: string, wordId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): Promise< (axios?: AxiosInstance, basePath?: string) => AxiosPromise @@ -408,8 +368,6 @@ export const AudioApiFp = function (configuration?: Configuration) { projectId, wordId, file, - name, - filePath, options ); return createRequestFunction( @@ -424,9 +382,7 @@ export const AudioApiFp = function (configuration?: Configuration) { * @param {string} projectId * @param {string} wordId * @param {string} speakerId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ @@ -434,9 +390,7 @@ export const AudioApiFp = function (configuration?: Configuration) { projectId: string, wordId: string, speakerId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): Promise< (axios?: AxiosInstance, basePath?: string) => AxiosPromise @@ -447,8 +401,6 @@ export const AudioApiFp = function (configuration?: Configuration) { wordId, speakerId, file, - name, - filePath, options ); return createRequestFunction( @@ -512,22 +464,18 @@ export const AudioApiFactory = function ( * * @param {string} projectId * @param {string} wordId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ uploadAudioFile( projectId: string, wordId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): AxiosPromise { return localVarFp - .uploadAudioFile(projectId, wordId, file, name, filePath, options) + .uploadAudioFile(projectId, wordId, file, options) .then((request) => request(axios, basePath)); }, /** @@ -535,9 +483,7 @@ export const AudioApiFactory = function ( * @param {string} projectId * @param {string} wordId * @param {string} speakerId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ @@ -545,21 +491,11 @@ export const AudioApiFactory = function ( projectId: string, wordId: string, speakerId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): AxiosPromise { return localVarFp - .uploadAudioFileWithSpeaker( - projectId, - wordId, - speakerId, - file, - name, - filePath, - options - ) + .uploadAudioFileWithSpeaker(projectId, wordId, speakerId, file, options) .then((request) => request(axios, basePath)); }, }; @@ -646,21 +582,7 @@ export interface AudioApiUploadAudioFileRequest { * @type {any} * @memberof AudioApiUploadAudioFile */ - readonly file: any; - - /** - * - * @type {string} - * @memberof AudioApiUploadAudioFile - */ - readonly name: string; - - /** - * - * @type {string} - * @memberof AudioApiUploadAudioFile - */ - readonly filePath: string; + readonly file?: any; } /** @@ -695,21 +617,7 @@ export interface AudioApiUploadAudioFileWithSpeakerRequest { * @type {any} * @memberof AudioApiUploadAudioFileWithSpeaker */ - readonly file: any; - - /** - * - * @type {string} - * @memberof AudioApiUploadAudioFileWithSpeaker - */ - readonly name: string; - - /** - * - * @type {string} - * @memberof AudioApiUploadAudioFileWithSpeaker - */ - readonly filePath: string; + readonly file?: any; } /** @@ -777,8 +685,6 @@ export class AudioApi extends BaseAPI { requestParameters.projectId, requestParameters.wordId, requestParameters.file, - requestParameters.name, - requestParameters.filePath, options ) .then((request) => request(this.axios, this.basePath)); @@ -801,8 +707,6 @@ export class AudioApi extends BaseAPI { requestParameters.wordId, requestParameters.speakerId, requestParameters.file, - requestParameters.name, - requestParameters.filePath, options ) .then((request) => request(this.axios, this.basePath)); diff --git a/src/api/api/avatar-api.ts b/src/api/api/avatar-api.ts index 301b5a7d84..902856942a 100644 --- a/src/api/api/avatar-api.ts +++ b/src/api/api/avatar-api.ts @@ -92,27 +92,17 @@ export const AvatarApiAxiosParamCreator = function ( /** * * @param {string} userId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ uploadAvatar: async ( userId: string, - file: any, - name: string, - filePath: string, + file?: any, options: any = {} ): Promise => { // verify required parameter 'userId' is not null or undefined assertParamExists("uploadAvatar", "userId", userId); - // verify required parameter 'file' is not null or undefined - assertParamExists("uploadAvatar", "file", file); - // verify required parameter 'name' is not null or undefined - assertParamExists("uploadAvatar", "name", name); - // verify required parameter 'filePath' is not null or undefined - assertParamExists("uploadAvatar", "filePath", filePath); const localVarPath = `/v1/users/{userId}/avatar/upload`.replace( `{${"userId"}}`, encodeURIComponent(String(userId)) @@ -136,15 +126,7 @@ export const AvatarApiAxiosParamCreator = function ( FormData)(); if (file !== undefined) { - localVarFormParams.append("File", file as any); - } - - if (name !== undefined) { - localVarFormParams.append("Name", name as any); - } - - if (filePath !== undefined) { - localVarFormParams.append("FilePath", filePath as any); + localVarFormParams.append("file", file as any); } localVarHeaderParameter["Content-Type"] = "multipart/form-data"; @@ -200,17 +182,13 @@ export const AvatarApiFp = function (configuration?: Configuration) { /** * * @param {string} userId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ async uploadAvatar( userId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): Promise< (axios?: AxiosInstance, basePath?: string) => AxiosPromise @@ -218,8 +196,6 @@ export const AvatarApiFp = function (configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.uploadAvatar( userId, file, - name, - filePath, options ); return createRequestFunction( @@ -257,21 +233,17 @@ export const AvatarApiFactory = function ( /** * * @param {string} userId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ uploadAvatar( userId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): AxiosPromise { return localVarFp - .uploadAvatar(userId, file, name, filePath, options) + .uploadAvatar(userId, file, options) .then((request) => request(axios, basePath)); }, }; @@ -309,21 +281,7 @@ export interface AvatarApiUploadAvatarRequest { * @type {any} * @memberof AvatarApiUploadAvatar */ - readonly file: any; - - /** - * - * @type {string} - * @memberof AvatarApiUploadAvatar - */ - readonly name: string; - - /** - * - * @type {string} - * @memberof AvatarApiUploadAvatar - */ - readonly filePath: string; + readonly file?: any; } /** @@ -361,13 +319,7 @@ export class AvatarApi extends BaseAPI { options?: any ) { return AvatarApiFp(this.configuration) - .uploadAvatar( - requestParameters.userId, - requestParameters.file, - requestParameters.name, - requestParameters.filePath, - options - ) + .uploadAvatar(requestParameters.userId, requestParameters.file, options) .then((request) => request(this.axios, this.basePath)); } } diff --git a/src/api/api/lift-api.ts b/src/api/api/lift-api.ts index f623850106..5fb4bcf10d 100644 --- a/src/api/api/lift-api.ts +++ b/src/api/api/lift-api.ts @@ -274,27 +274,17 @@ export const LiftApiAxiosParamCreator = function ( /** * * @param {string} projectId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ uploadLiftFile: async ( projectId: string, - file: any, - name: string, - filePath: string, + file?: any, options: any = {} ): Promise => { // verify required parameter 'projectId' is not null or undefined assertParamExists("uploadLiftFile", "projectId", projectId); - // verify required parameter 'file' is not null or undefined - assertParamExists("uploadLiftFile", "file", file); - // verify required parameter 'name' is not null or undefined - assertParamExists("uploadLiftFile", "name", name); - // verify required parameter 'filePath' is not null or undefined - assertParamExists("uploadLiftFile", "filePath", filePath); const localVarPath = `/v1/projects/{projectId}/lift/upload`.replace( `{${"projectId"}}`, encodeURIComponent(String(projectId)) @@ -318,15 +308,7 @@ export const LiftApiAxiosParamCreator = function ( FormData)(); if (file !== undefined) { - localVarFormParams.append("File", file as any); - } - - if (name !== undefined) { - localVarFormParams.append("Name", name as any); - } - - if (filePath !== undefined) { - localVarFormParams.append("FilePath", filePath as any); + localVarFormParams.append("file", file as any); } localVarHeaderParameter["Content-Type"] = "multipart/form-data"; @@ -349,17 +331,13 @@ export const LiftApiAxiosParamCreator = function ( /** * * @param {string} projectId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ uploadLiftFileAndGetWritingSystems: async ( projectId: string, - file: any, - name: string, - filePath: string, + file?: any, options: any = {} ): Promise => { // verify required parameter 'projectId' is not null or undefined @@ -368,16 +346,6 @@ export const LiftApiAxiosParamCreator = function ( "projectId", projectId ); - // verify required parameter 'file' is not null or undefined - assertParamExists("uploadLiftFileAndGetWritingSystems", "file", file); - // verify required parameter 'name' is not null or undefined - assertParamExists("uploadLiftFileAndGetWritingSystems", "name", name); - // verify required parameter 'filePath' is not null or undefined - assertParamExists( - "uploadLiftFileAndGetWritingSystems", - "filePath", - filePath - ); const localVarPath = `/v1/projects/{projectId}/lift/uploadandgetwritingsystems`.replace( `{${"projectId"}}`, @@ -402,15 +370,7 @@ export const LiftApiAxiosParamCreator = function ( FormData)(); if (file !== undefined) { - localVarFormParams.append("File", file as any); - } - - if (name !== undefined) { - localVarFormParams.append("Name", name as any); - } - - if (filePath !== undefined) { - localVarFormParams.append("FilePath", filePath as any); + localVarFormParams.append("file", file as any); } localVarHeaderParameter["Content-Type"] = "multipart/form-data"; @@ -557,17 +517,13 @@ export const LiftApiFp = function (configuration?: Configuration) { /** * * @param {string} projectId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ async uploadLiftFile( projectId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): Promise< (axios?: AxiosInstance, basePath?: string) => AxiosPromise @@ -575,8 +531,6 @@ export const LiftApiFp = function (configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.uploadLiftFile( projectId, file, - name, - filePath, options ); return createRequestFunction( @@ -589,17 +543,13 @@ export const LiftApiFp = function (configuration?: Configuration) { /** * * @param {string} projectId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ async uploadLiftFileAndGetWritingSystems( projectId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): Promise< ( @@ -611,8 +561,6 @@ export const LiftApiFp = function (configuration?: Configuration) { await localVarAxiosParamCreator.uploadLiftFileAndGetWritingSystems( projectId, file, - name, - filePath, options ); return createRequestFunction( @@ -697,47 +645,33 @@ export const LiftApiFactory = function ( /** * * @param {string} projectId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ uploadLiftFile( projectId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): AxiosPromise { return localVarFp - .uploadLiftFile(projectId, file, name, filePath, options) + .uploadLiftFile(projectId, file, options) .then((request) => request(axios, basePath)); }, /** * * @param {string} projectId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ uploadLiftFileAndGetWritingSystems( projectId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): AxiosPromise> { return localVarFp - .uploadLiftFileAndGetWritingSystems( - projectId, - file, - name, - filePath, - options - ) + .uploadLiftFileAndGetWritingSystems(projectId, file, options) .then((request) => request(axios, basePath)); }, }; @@ -831,21 +765,7 @@ export interface LiftApiUploadLiftFileRequest { * @type {any} * @memberof LiftApiUploadLiftFile */ - readonly file: any; - - /** - * - * @type {string} - * @memberof LiftApiUploadLiftFile - */ - readonly name: string; - - /** - * - * @type {string} - * @memberof LiftApiUploadLiftFile - */ - readonly filePath: string; + readonly file?: any; } /** @@ -866,21 +786,7 @@ export interface LiftApiUploadLiftFileAndGetWritingSystemsRequest { * @type {any} * @memberof LiftApiUploadLiftFileAndGetWritingSystems */ - readonly file: any; - - /** - * - * @type {string} - * @memberof LiftApiUploadLiftFileAndGetWritingSystems - */ - readonly name: string; - - /** - * - * @type {string} - * @memberof LiftApiUploadLiftFileAndGetWritingSystems - */ - readonly filePath: string; + readonly file?: any; } /** @@ -985,8 +891,6 @@ export class LiftApi extends BaseAPI { .uploadLiftFile( requestParameters.projectId, requestParameters.file, - requestParameters.name, - requestParameters.filePath, options ) .then((request) => request(this.axios, this.basePath)); @@ -1007,8 +911,6 @@ export class LiftApi extends BaseAPI { .uploadLiftFileAndGetWritingSystems( requestParameters.projectId, requestParameters.file, - requestParameters.name, - requestParameters.filePath, options ) .then((request) => request(this.axios, this.basePath)); diff --git a/src/api/api/speaker-api.ts b/src/api/api/speaker-api.ts index c0e30c4e08..86b20ac317 100644 --- a/src/api/api/speaker-api.ts +++ b/src/api/api/speaker-api.ts @@ -436,30 +436,20 @@ export const SpeakerApiAxiosParamCreator = function ( * * @param {string} projectId * @param {string} speakerId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ uploadConsent: async ( projectId: string, speakerId: string, - file: any, - name: string, - filePath: string, + file?: any, options: any = {} ): Promise => { // verify required parameter 'projectId' is not null or undefined assertParamExists("uploadConsent", "projectId", projectId); // verify required parameter 'speakerId' is not null or undefined assertParamExists("uploadConsent", "speakerId", speakerId); - // verify required parameter 'file' is not null or undefined - assertParamExists("uploadConsent", "file", file); - // verify required parameter 'name' is not null or undefined - assertParamExists("uploadConsent", "name", name); - // verify required parameter 'filePath' is not null or undefined - assertParamExists("uploadConsent", "filePath", filePath); const localVarPath = `/v1/projects/{projectId}/speakers/consent/{speakerId}` .replace(`{${"projectId"}}`, encodeURIComponent(String(projectId))) @@ -483,15 +473,7 @@ export const SpeakerApiAxiosParamCreator = function ( FormData)(); if (file !== undefined) { - localVarFormParams.append("File", file as any); - } - - if (name !== undefined) { - localVarFormParams.append("Name", name as any); - } - - if (filePath !== undefined) { - localVarFormParams.append("FilePath", filePath as any); + localVarFormParams.append("file", file as any); } localVarHeaderParameter["Content-Type"] = "multipart/form-data"; @@ -730,18 +712,14 @@ export const SpeakerApiFp = function (configuration?: Configuration) { * * @param {string} projectId * @param {string} speakerId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ async uploadConsent( projectId: string, speakerId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): Promise< (axios?: AxiosInstance, basePath?: string) => AxiosPromise @@ -750,8 +728,6 @@ export const SpeakerApiFp = function (configuration?: Configuration) { projectId, speakerId, file, - name, - filePath, options ); return createRequestFunction( @@ -905,22 +881,18 @@ export const SpeakerApiFactory = function ( * * @param {string} projectId * @param {string} speakerId - * @param {any} file - * @param {string} name - * @param {string} filePath + * @param {any} [file] * @param {*} [options] Override http request option. * @throws {RequiredError} */ uploadConsent( projectId: string, speakerId: string, - file: any, - name: string, - filePath: string, + file?: any, options?: any ): AxiosPromise { return localVarFp - .uploadConsent(projectId, speakerId, file, name, filePath, options) + .uploadConsent(projectId, speakerId, file, options) .then((request) => request(axios, basePath)); }, }; @@ -1112,21 +1084,7 @@ export interface SpeakerApiUploadConsentRequest { * @type {any} * @memberof SpeakerApiUploadConsent */ - readonly file: any; - - /** - * - * @type {string} - * @memberof SpeakerApiUploadConsent - */ - readonly name: string; - - /** - * - * @type {string} - * @memberof SpeakerApiUploadConsent - */ - readonly filePath: string; + readonly file?: any; } /** @@ -1305,8 +1263,6 @@ export class SpeakerApi extends BaseAPI { requestParameters.projectId, requestParameters.speakerId, requestParameters.file, - requestParameters.name, - requestParameters.filePath, options ) .then((request) => request(this.axios, this.basePath)); diff --git a/src/backend/index.ts b/src/backend/index.ts index 8ccc6abe46..ce63fe05fc 100644 --- a/src/backend/index.ts +++ b/src/backend/index.ts @@ -109,30 +109,30 @@ const userEditApi = new Api.UserEditApi(config, BASE_PATH, axiosInstance); const userRoleApi = new Api.UserRoleApi(config, BASE_PATH, axiosInstance); const wordApi = new Api.WordApi(config, BASE_PATH, axiosInstance); -// Backend controllers receiving a file via a "[FromForm] FileUpload fileUpload" param -// have the internal fields expanded by openapi-generator as params in our Api. -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -function fileUpload(file: File) { - return { file, filePath: "", name: "" }; -} - function defaultOptions(): object { return { headers: authHeader() }; } +function fileUploadOptions(): object { + return { + headers: { ...authHeader(), "content-type": "multipart/form-data" }, + }; +} + /* AudioController.cs */ export async function uploadAudio( wordId: string, file: FileWithSpeakerId ): Promise { + console.info(file); const projectId = LocalStorage.getProjectId(); const speakerId = file.speakerId ?? ""; - const params = { projectId, wordId, ...fileUpload(file) }; - const headers = { ...authHeader(), "content-type": "application/json" }; + const params = { projectId, wordId, file }; + const options = fileUploadOptions(); const promise = speakerId - ? audioApi.uploadAudioFileWithSpeaker({ ...params, speakerId }, { headers }) - : audioApi.uploadAudioFile(params, { headers }); + ? audioApi.uploadAudioFileWithSpeaker({ ...params, speakerId }, options) + : audioApi.uploadAudioFile(params, options); return (await promise).data; } @@ -151,12 +151,8 @@ export function getAudioUrl(wordId: string, fileName: string): string { /* AvatarController.cs */ -export async function uploadAvatar( - userId: string, - imgFile: File -): Promise { - const headers = { ...authHeader(), "content-type": "application/json" }; - await avatarApi.uploadAvatar({ userId, ...fileUpload(imgFile) }, { headers }); +export async function uploadAvatar(userId: string, file: File): Promise { + await avatarApi.uploadAvatar({ userId, file }, fileUploadOptions()); if (userId === LocalStorage.getUserId()) { LocalStorage.setAvatar(await avatarSrc(userId)); } @@ -229,11 +225,11 @@ export async function validateLink( /** Upload a LIFT file during project creation to get vernacular ws options. */ export async function uploadLiftAndGetWritingSystems( - liftFile: File + file: File ): Promise { const resp = await liftApi.uploadLiftFileAndGetWritingSystems( - { projectId: "nonempty", ...fileUpload(liftFile) }, - { headers: { ...authHeader(), "Content-Type": "multipart/form-data" } } + { projectId: "nonempty", file }, + fileUploadOptions() ); return resp.data; } @@ -247,11 +243,11 @@ export async function finishUploadLift(projectId: string): Promise { /** Upload a LIFT file and add its data to the specified project. */ export async function uploadLift( projectId: string, - liftFile: File + file: File ): Promise { const resp = await liftApi.uploadLiftFile( - { projectId, ...fileUpload(liftFile) }, - { headers: { ...authHeader(), "Content-Type": "multipart/form-data" } } + { projectId, file }, + fileUploadOptions() ); return resp.data; } @@ -542,9 +538,8 @@ export async function uploadConsent( file: File ): Promise { const { id, projectId } = speaker; - const params = { projectId, speakerId: id, ...fileUpload(file) }; - const headers = { ...authHeader(), "content-type": "application/json" }; - return (await speakerApi.uploadConsent(params, { headers })).data; + const params = { projectId, speakerId: id, file }; + return (await speakerApi.uploadConsent(params, fileUploadOptions())).data; } /** Use of the returned url acts as an HttpGet. */