Example #1
0
        public async Task <IActionResult> GetAttachedFiles(long id, [FromQuery] bool withUrl = false)
        {
            //データの存在チェック
            var inferenceHistory = await inferenceHistoryRepository.GetByIdAsync(id);

            if (inferenceHistory == null)
            {
                return(JsonNotFound($"Inference ID {id} is not found."));
            }

            var underDir = await storageLogic.GetUnderDirAsync(ResourceType.InferenceContainerAttachedFiles, $"{id}/");

            if (underDir.IsSuccess == false)
            {
                return(JsonError(HttpStatusCode.ServiceUnavailable, "Failed to access the storage service. Please contact to system administrators."));
            }

            var containerAttachedFiles = new List <AttachedFileOutputModel>();

            containerAttachedFiles.AddRange(underDir.Value.Files.Select(
                                                f => new AttachedFileOutputModel(inferenceHistory.Id, f.FileName, -1)
            {
                Url      = withUrl ? storageLogic.GetPreSignedUriForGetFromKey(f.Key, f.FileName, true).ToString() : null,
                IsLocked = true
            }
                                                ));

            var userAttachedFiles = new List <AttachedFileOutputModel>();

            var filesOnDB = await inferenceHistoryRepository.GetAllAttachedFilesAsync(id);

            userAttachedFiles.AddRange(filesOnDB.Select(
                                           f => new AttachedFileOutputModel(inferenceHistory.Id, f.FileName, f.Id)
            {
                Url      = withUrl ? storageLogic.GetPreSignedUriForGet(ResourceType.InferenceHistoryAttachedFiles, f.StoredPath, f.FileName, true).ToString() : null,
                IsLocked = false
            }
                                           ));

            var result = containerAttachedFiles.Concat(userAttachedFiles);

            return(JsonOK(result));
        }