示例#1
0
        /// <summary>
        /// 指定したIDの全ファイル情報を取得する。
        /// </summary>
        /// <param name="dataId">データID</param>
        /// <param name="withUrl">結果にダウンロード用のURLを含めるか</param>
        public IEnumerable <DataFileOutputModel> GetDataFiles(long dataId, bool withUrl)
        {
            var result     = new List <DataFileOutputModel>();
            var properties = dataRepository.GetAllDataProperty(dataId);

            foreach (var property in properties)
            {
                var model = new DataFileOutputModel {
                    Id = dataId, Key = property.Key, FileId = property.Id, FileName = property.DataFile.FileName
                };

                if (withUrl)
                {
                    model.Url = storageLogic.GetPreSignedUriForGet(ResourceType.Data, property.DataFile.StoredPath, property.DataFile.FileName, true).ToString();
                }
                result.Add(model);
            }

            return(result);
        }
示例#2
0
        public IActionResult GetStorageUrl(string type, string storedPath, string fileName, bool secure)
        {
            ResourceType resourceType;

            if (string.IsNullOrEmpty(storedPath) || Enum.TryParse <ResourceType>(type, true, out resourceType) == false)
            {
                return(JsonBadRequest("Invalid inputs."));
            }

            string url = storageLogic.GetPreSignedUriForGet(resourceType, storedPath, fileName, secure == false).ToString();

            return(JsonOK(new { Url = url }));
        }
示例#3
0
        public IActionResult GetFileUrl(long id, string name)
        {
            //データの存在チェック
            var property = dataRepository.GetDataProperty(id, name);

            if (property == null || property.DataFile == null)
            {
                return(JsonNotFound($"Data ID {id} or file name {name} is not found."));
            }

            string url = storageLogic.GetPreSignedUriForGet(ResourceType.Data, property.DataFile.StoredPath, property.DataFile.FileName, true).ToString();

            return(JsonOK(new DataFileOutputModel {
                Id = id, Url = url, Key = name, FileId = property.Id, FileName = property.DataFile.FileName
            }));
        }
        public async Task <IActionResult> GetAttachedFiles(long id, [FromQuery] bool withUrl = false)
        {
            //データの存在チェック
            var trainingHistory = await trainingHistoryRepository.GetByIdAsync(id);

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

            var underDir = await storageLogic.GetUnderDirAsync(ResourceType.TrainingContainerAttachedFiles, $"{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(trainingHistory.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 trainingHistoryRepository.GetAllAttachedFilesAsync(id);

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

            var result = containerAttachedFiles.Concat(userAttachedFiles);

            return(JsonOK(result));
        }
        public async Task <IActionResult> GetAttachedFiles(long id, long dataId, bool withUrl)
        {
            // データの存在チェック
            var preprocessHistory = await preprocessHistoryRepository.GetPreprocessIncludeDataAndPreprocessAsync(id, dataId);

            if (preprocessHistory == null)
            {
                return(JsonNotFound($"Preprocessing History {preprocessHistory.Id} is not opened."));
            }

            string fileName = $"preproc_stdout_stderr_{id}_{dataId}.log";

            var result = new PreprocessAttachedFileOutputModel(preprocessHistory.Id, fileName, -1)
            {
                Url      = withUrl? storageLogic.GetPreSignedUriForGet(ResourceType.PreprocContainerAttachedFiles, $"{preprocessHistory.Id}/{fileName}", fileName, true).ToString() : null,
                IsLocked = true
            };

            return(JsonOK(result));
        }