ITPub博客

首页 > 人工智能 > 人工智能 > 智汀云盘-网盘开发golagn:共享文件

智汀云盘-网盘开发golagn:共享文件

原创 人工智能 作者:智汀科技 时间:2022-01-21 11:13:55 0 删除 编辑

 1. 共享文件夹列表

从 数据库中获取别人共享的文件:

whereStr := fmt.Sprintf("auth.uid = %d and auth.read = 1 and auth.is_share = 1", user.UserID)
folderList, err := entity.GetRelateFolderList(whereStr, req.PageOffset, req.PageSize)

并将切片内的赋值到返回切片中:

for _, folderRow := range folderList {
    isFamilyPath := 0
    if filepath.Base(folderRow.AbsPath) == types.FolderFamilyDir {
        isFamilyPath = 1
    }
    list = append(list, Info{
        ID:       folderRow.Id,
        Name:     folderRow.Name,
        Path:     fmt.Sprintf("/s/%d", folderRow.Id),
        FromUser: folderRow.FromUser,
        Read:     folderRow.Read,
        Write:    folderRow.Write,
        Deleted:  folderRow.Deleted,
        IsFamilyPath: isFamilyPath,
    })
}

2. 共享文件资源

共享文件夹设置成分享时,需要将原权限删除,并重新组建一个新的权限数组写入至数据库中。

// path转换为实际路径
folderId, err = utils.GetAbsFolderIdFromPath(path)
for _, uID := range req.ToUsers {
    // 权限存在则删除
    err = entity.DelFolderAuthByUidAndFolderId(uID, folderId)
    folderAuthCreate := entity.FolderAuth{
        Uid:      uID,
        FromUser: nickname,
        IsShare:  1,
        FolderId: folderId,
        Read:     req.Read,
        Write:    req.Write,
        Deleted:  req.Deleted,
    }
    folderAuthCreates = append(folderAuthCreates, folderAuthCreate)
}
if folderAuthCreates != nil {
    if err = entity.BatchInsertAuth(entity.GetDB(), folderAuthCreates); err != nil {
        err = errors.Wrap(err, errors.InternalServerErr)
        return
    }
}

3.惯例

如果你对本文有任何疑问或者高见,关注智汀公众号共同交流探讨(欢迎加入微信号:13326423643可以免费赠送“智能开关或其他智能硬件”哦)。


 

 


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70009085/viewspace-2853353/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2021-10-28

  • 博文量
    17
  • 访问量
    6917