MCPcopy Index your code
hub / github.com/TruthHun/BookStack / DownloadAttachment

Method DownloadAttachment

controllers/DocumentController.go:899–949  ·  view source on GitHub ↗

DownloadAttachment 下载附件.

()

Source from the content-addressed store, hash-verified

897
898// DownloadAttachment 下载附件.
899func (this *DocumentController) DownloadAttachment() {
900 identify := this.Ctx.Input.Param(":key")
901 attachId, _ := strconv.Atoi(this.Ctx.Input.Param(":attach_id"))
902 token := this.GetString("token")
903
904 memberId := 0
905
906 if this.Member != nil {
907 memberId = this.Member.MemberId
908 }
909 bookId := 0
910
911 //判断用户是否参与了书籍
912 bookResult, err := models.NewBookResult().FindByIdentify(identify, memberId)
913
914 if err != nil {
915 //判断书籍公开状态
916 book, err := models.NewBook().FindByFieldFirst("identify", identify)
917 if err != nil {
918 this.Abort("404")
919 }
920 //如果不是超级管理员则判断权限
921 if this.Member == nil || this.Member.Role != conf.MemberSuperRole {
922 //如果书籍是私有的,并且token不正确
923 if (book.PrivatelyOwned == 1 && token == "") || (book.PrivatelyOwned == 1 && book.PrivateToken != token) {
924 this.Abort("404")
925 }
926 }
927
928 bookId = book.BookId
929 } else {
930 bookId = bookResult.BookId
931 }
932 //查找附件
933 attachment, err := models.NewAttachment().Find(attachId)
934
935 if err != nil {
936 beego.Error("DownloadAttachment => ", err)
937 if err == orm.ErrNoRows {
938 this.Abort("404")
939 } else {
940 this.Abort("404")
941 }
942 }
943 if attachment.BookId != bookId {
944 this.Abort("404")
945 }
946 this.Ctx.Output.Download(strings.TrimLeft(attachment.FilePath, "./"), attachment.FileName)
947
948 this.StopRun()
949}
950
951// 删除附件.
952func (this *DocumentController) RemoveAttachment() {

Callers

nothing calls this directly

Calls 7

NewBookResultFunction · 0.92
NewBookFunction · 0.92
NewAttachmentFunction · 0.92
DownloadMethod · 0.80
FindByIdentifyMethod · 0.45
FindByFieldFirstMethod · 0.45
FindMethod · 0.45

Tested by

no test coverage detected