public object Patch([FromBody] dynamic model, string id) { FileId fileId = FileId.FromUuid(id); if (!_provider.FileExists(fileId.PhysicalPath) && !_provider.DirectoryExists(fileId.PhysicalPath)) { return(NotFound()); } dynamic result = null; switch (FilesHelper.GetFileType(fileId.PhysicalPath)) { case FileType.File: result = PatchFile(model, fileId); break; case FileType.Directory: result = PatchDirectory(model, fileId); break; default: return(new StatusCodeResult((int)HttpStatusCode.MethodNotAllowed)); } if (result.id != id) { return(LocationChanged(FilesHelper.GetLocation(result.id), result)); } return(result); }
public object Patch([FromBody] dynamic model, string id) { FileId fileId = FileId.FromUuid(id); IFileInfo info = _helper.GetExistingFileInfo(fileId.PhysicalPath); if (info == null) { return(NotFound()); } dynamic result = null; switch (info.Type) { case FileType.File: result = _helper.ToJsonModel(_helper.UpdateFile(model, info)); break; case FileType.Directory: result = _helper.ToJsonModel(_helper.UpdateDirectory(model, info)); break; default: return(new StatusCodeResult((int)HttpStatusCode.MethodNotAllowed)); } if (result.id != id) { return(LocationChanged(FilesHelper.GetLocation(result.id), result)); } return(result); }
public object Get(string id) { FileId fileId = FileId.FromUuid(id); if (!_provider.FileExists(fileId.PhysicalPath) && !_provider.DirectoryExists(fileId.PhysicalPath)) { return(NotFound()); } return(_helper.ToJsonModel(fileId.PhysicalPath)); }
public void EnsurePostModelValid(dynamic model, out string name, out FileId fileId, out FileId parentId) { if (model == null) { throw new ApiArgumentException("model"); } // // file if (model.file == null) { throw new ApiArgumentException("file"); } if (!(model.file is JObject)) { throw new ApiArgumentException("file", ApiArgumentException.EXPECTED_OBJECT); } string fileUuid = DynamicHelper.Value(model.file.id); if (fileUuid == null) { throw new ApiArgumentException("file.id"); } // // parent if (model.parent == null) { throw new ApiArgumentException("parent"); } if (!(model.parent is JObject)) { throw new ApiArgumentException("parent", ApiArgumentException.EXPECTED_OBJECT); } string parentUuid = DynamicHelper.Value(model.parent.id); if (parentUuid == null) { throw new ApiArgumentException("parent.id"); } // // name name = DynamicHelper.Value(model.name); if (!string.IsNullOrEmpty(name) && !PathUtil.IsValidFileName(name)) { throw new ApiArgumentException("name"); } fileId = FileId.FromUuid(fileUuid); parentId = FileId.FromUuid(parentUuid); }
public async Task Delete(string id) { FileId fileId = FileId.FromUuid(id); ILocation location = _helper.Options.Locations.FirstOrDefault(l => l.Path.Equals(fileId.PhysicalPath, StringComparison.OrdinalIgnoreCase)); if (location != null) { await _helper.RemoveLocation(location); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
public object Get(string id) { FileId fileId = FileId.FromUuid(id); ILocation location = _helper.Options.Locations.FirstOrDefault(l => l.Path.Equals(fileId.PhysicalPath, StringComparison.OrdinalIgnoreCase)); if (location == null) { return(NotFound()); } return(_helper.ToJsonModel(location)); }
public IActionResult Delete(string id) { FileId fileId = FileId.FromUuid(id); IFileInfo info = _helper.GetExistingFileInfo(fileId.PhysicalPath); if (info != null) { _provider.Delete(info); } return(new NoContentResult()); }
public object Get(string id) { FileId fileId = FileId.FromUuid(id); IFileInfo info = _helper.GetExistingFileInfo(fileId.PhysicalPath); if (info == null) { return(NotFound()); } return(_helper.ToJsonModel(info)); }
public async Task <IActionResult> Put(string id) { FileId fileId = FileId.FromUuid(id); if (!_fileProvider.FileExists(fileId.PhysicalPath)) { return(NotFound()); } AddHttpLinkHeader(fileId); await Context.Response.PutFileContentAsync(fileId.PhysicalPath, _fileProvider); return(new EmptyResult()); }
public IActionResult Head(string id) { FileId fileId = FileId.FromUuid(id); if (!_fileProvider.FileExists(fileId.PhysicalPath)) { return(NotFound()); } AddHttpLinkHeader(fileId); Context.Response.WriteFileContentHeaders(fileId.PhysicalPath, _fileProvider); return(new EmptyResult()); }
public IActionResult Post([FromBody] dynamic model) { if (_downloadService == null) { throw new NotFoundException(typeof(IDownloadService).GetTypeInfo().Assembly.FullName); } if (model == null) { throw new ApiArgumentException("model"); } if (model.file == null) { throw new ApiArgumentException("file"); } if (!(model.file is JObject)) { throw new ApiArgumentException("file", ApiArgumentException.EXPECTED_OBJECT); } // // Check Id string fileUuid = DynamicHelper.Value(model.file.id); if (fileUuid == null) { throw new ApiArgumentException("file.id"); } int?ttl = DynamicHelper.To <int>(model.ttl); FileId fileId = FileId.FromUuid(fileUuid); IFileInfo file = _fileService.GetFile(fileId.PhysicalPath); if (!file.Exists) { throw new NotFoundException(fileId.PhysicalPath); } var dl = _downloadService.Create(file.Path, ttl ?? DEFAULT_DOWNLOAD_TIMEOUT); // Inform client location points to downloadable attachment Context.Response.Headers.Add("Pragma", "attachment"); return(Created(dl.Href, null)); }
private void PreGet(out FileId parentId, out string name, out string physicalPath, out Fields fields) { string parentUuid = Context.Request.Query[Defines.PARENT_IDENTIFIER]; name = Context.Request.Query[_nameKey]; physicalPath = Context.Request.Query[_physicalPathKey]; fields = Context.Request.GetFields(); if (!string.IsNullOrEmpty(name)) { if (name.IndexOfAny(PathUtil.InvalidFileNameChars) != -1) { throw new ApiArgumentException(_nameKey); } } parentId = string.IsNullOrEmpty(parentUuid) ? null : FileId.FromUuid(parentUuid); }
public IActionResult Delete(string id) { FileId fileId = FileId.FromUuid(id); if (_provider.FileExists(fileId.PhysicalPath) || _provider.DirectoryExists(fileId.PhysicalPath)) { switch (FilesHelper.GetFileType(fileId.PhysicalPath)) { case FileType.File: case FileType.Directory: _provider.Delete(fileId.PhysicalPath); break; default: break; } } return(new NoContentResult()); }
public async Task <object> Patch([FromBody] dynamic model, string id) { FileId fileId = FileId.FromUuid(id); ILocation location = _helper.Options.Locations.FirstOrDefault(l => l.Path.Equals(fileId.PhysicalPath, StringComparison.OrdinalIgnoreCase)); if (location == null) { return(NotFound()); } location = await _helper.UpdateLocation(model, location); dynamic locModel = _helper.ToJsonModel(location); if (locModel.id != id) { return(LocationChanged(_helper.GetLocationPath(locModel.id), locModel)); } return(locModel); }
public object Post([FromBody] dynamic model) { if (model == null) { throw new ApiArgumentException("model"); } if (model.parent == null) { throw new ApiArgumentException("parent"); } if (!(model.parent is JObject)) { throw new ApiArgumentException("parent", ApiArgumentException.EXPECTED_OBJECT); } // // Check Id string parentUuid = DynamicHelper.Value(model.parent.id); if (parentUuid == null) { throw new ApiArgumentException("parent.id"); } FileId fileId = FileId.FromUuid(parentUuid); if (!_provider.DirectoryExists(fileId.PhysicalPath)) { throw new NotFoundException("parent"); } // // Check Name string name = DynamicHelper.Value(model.name); if (!PathUtil.IsValidFileName(name)) { throw new ApiArgumentException("model.name"); } // // Check Type string type = DynamicHelper.Value(model.type); FileType fileType; if (type == null || !Enum.TryParse(type, true, out fileType)) { throw new ApiArgumentException("model.type"); } DateTime?created = DynamicHelper.To <DateTime>(model.created); DateTime?lastAccess = DynamicHelper.To <DateTime>(model.last_access); DateTime?lastModified = DynamicHelper.To <DateTime>(model.last_modified); var creationPath = Path.Combine(fileId.PhysicalPath, name); if (_provider.DirectoryExists(creationPath) || _provider.FileExists(creationPath)) { throw new AlreadyExistsException("name"); } IFileInfo info = fileType == FileType.File ? _provider.CreateFile(creationPath) : _provider.CreateDirectory(creationPath); _provider.SetFileTime(info.Path, lastAccess, lastModified, created); dynamic file = _helper.ToJsonModel(info); return(Created(FilesHelper.GetLocation(file.id), _helper.ToJsonModel(info))); }