[Authorize]//會員可以取得所有使用者的清單,用以查詢各使用分享可供存取的檔案節點 public JsonResult UserList( [FromQuery]UserAuthority authority = UserAuthority.User, [FromQuery]int index = 0, [FromQuery]int length = 10) { var userList = from t in Database.User where t.Authority == authority select t; var result = new ApiResult() { Result = userList.Skip(index).Take(length) }; result.Type.Count = userList.Count(); result.Type.Index = index; result.Type.Length = length; return result; }
public async Task Invoke(HttpContext context) { try { await this.next.Invoke(context); } catch (Exception e) { if (e.Message == "No authentication handler is configured to handle the scheme: Automatic") { ApiResult authResult = new ApiResult() { Result = new AuthorizeException() }; if (Startup.ExceptionHttpStatusCode) { context.Response.StatusCode = 403; }else { context.Response.StatusCode = 200; } context.Response.ContentType = "application/json"; await context.Response.WriteAsync(authResult.ToString()); } } }
public JsonResult Children( FileNode target, [FromQuery]int index = 0, [FromQuery]int length = 10, [FromQuery]OrderTypes order = OrderTypes.DirFirst) { if (!target.HasReadAuthority(User, Database)) { throw new AuthorizeException("無權限存取該目標"); } if (target.IsFile) throw new ApiInvalidOperationException("檔案無子系"); var data = target.GetChildren(Database); if (order == OrderTypes.DirFirst) { data = from t in data orderby t.IsFile, t.Ext, t.Name select t; } else if (order == OrderTypes.FileFirst) { data = from t in data orderby t.IsFile, t.Ext descending, t.Name select t; } var result = new ApiResult() { Result = data.Skip(index).Take(length) }; result.Type.Index = index; result.Type.Length = length; result.Type.Count = data.Count(); return result; }
public JsonResult GeneratePreviewKey(FileNode target) { if (!target.HasReadAuthority(User, Database)) { throw new AuthorizeException("無權限存取該目標"); } if (!target.IsFile) throw new ApiInvalidOperationException($"目標節點不應該為目錄"); var ExpireTime = DateTime.Now.AddMinutes(10); Guid Key = PreviewKeyCheck.Create(target.Id, ExpireTime); var result = new ApiResult() { Result = new { TargetId = target.Id, Key = Key, ExpireTime = ExpireTime } }; result.Type.Name = "PreviewKey"; return result; }
public JsonResult GroupShareList( Group target, [FromQuery]int index = 0, [FromQuery]int length = 10, [FromQuery]OrderTypes order = OrderTypes.DirFirst) { if (target == null) throw new ApiArgumentException($"{nameof(target)}不該為null"); if (!target.IsMember(User, Database)) throw new AuthorizeException("必須是成員"); var data = from t in Database.FileNode.Include(x => x.Parent) where t.GroupId == target.Id && t.Parent.GroupId != target.Id select t; if (order == OrderTypes.DirFirst) { data = from t in data orderby t.IsFile, t.Ext, t.Name select t; } else if (order == OrderTypes.FileFirst) { data = from t in data orderby t.IsFile, t.Ext descending, t.Name select t; } var result = new ApiResult() { Result = data.Skip(index).Take(length) }; result.Type.Index = index; result.Type.Length = length; result.Type.Count = data.Count(); return result; }
public JsonResult DeepSearch( User target, [FromQuery]string keyword = "", [FromQuery]int index = 0, [FromQuery]int length = 10, [FromQuery]OrderTypes order = OrderTypes.DirFirst) { if (target == null) target = this.User; if (target.Id != this.User.Id) throw new AuthorizeException("深度搜尋僅限搜尋使用者自身"); var data = from t in Database.FileNode where t.OwnerId == target.Id select t; if (order == OrderTypes.DirFirst) { data = from t in data orderby t.IsFile, t.Ext, t.Name select t; } else if (order == OrderTypes.FileFirst) { data = from t in data orderby t.IsFile, t.Ext descending, t.Name select t; } var result = new ApiResult() { Result = data.Skip(index).Take(length) }; result.Type.Index = index; result.Type.Length = length; result.Type.Count = data.Count(); return result; }
public JsonResult Search( FileNode target = null, [FromQuery]string keyword = "", [FromQuery]int index = 0, [FromQuery]int length = 10, [FromQuery]OrderTypes order = OrderTypes.DirFirst) { if (target == null && !IsLogin) throw new AuthorizeException(); if (target == null) { target = User.GetRootFileNode(Database); } if (target.IsFile) throw new ApiInvalidOperationException("檔案無子系"); if (!target.HasReadAuthority(User, Database)) { throw new AuthorizeException("無權限存取該目標"); } IQueryable<FileNode> data = Database.FileNode.Where(x => x.OwnerId == User.Id).Where(x => x.Name.Contains(keyword)); if (target != null) { data = from t in Database.FileNode where t.ParentId == target.Id && t.Name.Contains(keyword) select t; } if (order == OrderTypes.DirFirst) { data = from t in data orderby t.IsFile, t.Ext, t.Name select t; } else if (order == OrderTypes.FileFirst) { data = from t in data orderby t.IsFile, t.Ext descending, t.Name select t; } var result = new ApiResult() { Result = data.Skip(index).Take(length) }; result.Type.Index = index; result.Type.Length = length; result.Type.Count = data.Count(); return result; }
public JsonResult GetOwnList( User target = null, [FromQuery]string keyword = "", [FromQuery]int index = 0, [FromQuery]int length = 10) { if (target == null) target = User; if (User.Authority != UserAuthority.Admin && target.Id != User.Id) { throw new AuthorizeException("僅管理者可查看其餘使用者群組"); } keyword = keyword.Trim(); var data = from t in Database.Group where t.OwnerId == target.Id && t.Name.Contains(keyword) orderby t.Name select t; var result = new ApiResult() { Result = data.Skip(index).Take(length) }; result.Type.Index = index; result.Type.Length = length; result.Type.Count = data.Count(); return result; }
public JsonResult GetMembers( Group target, [FromQuery]string keyword = "", [FromQuery]int index = 0, [FromQuery]int length = 10) { if (target == null) throw new ApiArgumentException($"{nameof(target)}不該為null"); if (User.Authority != UserAuthority.Admin && !target.IsMember(User, Database)) { throw new AuthorizeException(); } keyword = keyword.Trim(); var data = target.GetMembers(Database).Where(x => x.Name.Contains(keyword) || x.Id.Contains(keyword)); data = data.OrderBy(x => x.Name); var result = new ApiResult() { Result = data.Skip(index).Take(length) }; result.Type.Index = index; result.Type.Length = length; result.Type.Count = data.Count(); return result; }
public JsonResult GetAllList( [FromQuery]string keyword = "", [FromQuery]int index = 0, [FromQuery]int length = 10) { keyword = keyword.Trim(); IQueryable<Group> filterGroup = Database.Group .Where(x => x.Name.Contains(keyword)) .OrderBy(x => x.Name); var result = new ApiResult() { Result = filterGroup.Skip(index).Take(length) }; result.Type.Index = 0; result.Type.Length = length; result.Type.Count = filterGroup.Count(); return result; }