Exemplo n.º 1
0
        public async Task <IActionResult> GetUnderDir(long id, [FromQuery] string path = "/", [FromQuery] bool withUrl = false)
        {
            //データの存在チェック
            var trainingHistory = await trainingHistoryRepository.GetByIdAsync(id);

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

            // 検索path文字列の先頭・末尾が/でない場合はつける
            if (!path.StartsWith("/", StringComparison.CurrentCulture))
            {
                path = "/" + path;
            }
            if (!path.EndsWith("/", StringComparison.CurrentCulture))
            {
                path = path + "/";
            }

            // windowsから実行された場合、区切り文字が"\\"として送られてくるので"/"に置換する
            path = path.Replace("\\", "/");

            var rootDir = $"{id}" + path;

            var result = await storageLogic.GetUnderDirAsync(ResourceType.TrainingContainerOutputFiles, rootDir);

            if (withUrl)
            {
                result.Value.Files.ForEach(x => x.Url = storageLogic.GetPreSignedUriForGetFromKey(x.Key, x.FileName, true).ToString());
            }


            return(JsonOK(result.Value));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetUnderDir(long id, [FromQuery] string path = "/", [FromQuery] bool withUrl = false)
        {
            //データの存在チェック
            var notebookHistory = await notebookHistoryRepository.GetByIdAsync(id);

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

            if (!Regex.IsMatch(path, "[-_1-9a-zA-Z/]+"))
            {
                return(JsonBadRequest("Invalid path. allowed characters are -_1-9a-zA-Z/"));
            }

            // 検索path文字列の先頭・末尾が/でない場合はつける
            if (!path.StartsWith("/"))
            {
                path = "/" + path;
            }
            if (!path.EndsWith("/"))
            {
                path = path + "/";
            }
            var rootDir = $"{id}" + path;

            var result = await storageLogic.GetUnderDirAsync(ResourceType.NotebookContainerOutputFiles, rootDir);

            if (withUrl)
            {
                result.Value.Files.ForEach(x => x.Url = storageLogic.GetPreSignedUriForGetFromKey(x.Key, x.FileName, true).ToString());
            }

            return(JsonOK(result.Value));
        }