|
|
|
@@ -664,94 +664,3 @@ func Attachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error) { |
|
|
|
|
|
|
|
return attachments, count, nil |
|
|
|
} |
|
|
|
|
|
|
|
func MyFvAttachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error) { |
|
|
|
sess := x.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
|
|
|
|
var cond = builder.NewCond() |
|
|
|
if opts.NeedDatasetIDs { |
|
|
|
cond = cond.And( |
|
|
|
builder.In("attachment.dataset_id", opts.DatasetIDs), |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
if opts.UploaderID > 0 { |
|
|
|
cond = cond.And( |
|
|
|
builder.Eq{"attachment.uploader_id": opts.UploaderID}, |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
if (opts.Type) >= 0 { |
|
|
|
cond = cond.And( |
|
|
|
builder.Eq{"attachment.type": opts.Type}, |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
if opts.NeedIsPrivate { |
|
|
|
cond = cond.And( |
|
|
|
builder.Eq{"attachment.is_private": opts.IsPrivate}, |
|
|
|
) |
|
|
|
} |
|
|
|
if opts.RecommendOnly { |
|
|
|
cond = cond.And(builder.In("attachment.id", builder.Select("attachment.id"). |
|
|
|
From("attachment"). |
|
|
|
Join("INNER", "dataset", "attachment.dataset_id = dataset.id and dataset.recommend=true"))) |
|
|
|
} |
|
|
|
|
|
|
|
if opts.JustNeedZipFile { |
|
|
|
var DecompressState []int32 |
|
|
|
DecompressState = append(DecompressState, DecompressStateDone, DecompressStateIng, DecompressStateFailed) |
|
|
|
cond = cond.And( |
|
|
|
builder.In("attachment.decompress_state", DecompressState), |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
var count int64 |
|
|
|
var err error |
|
|
|
if len(opts.Keyword) == 0 { |
|
|
|
count, err = sess.Where(cond).Count(new(Attachment)) |
|
|
|
} else { |
|
|
|
lowerKeyWord := strings.ToLower(opts.Keyword) |
|
|
|
|
|
|
|
cond = cond.And(builder.Or(builder.Like{"LOWER(attachment.name)", lowerKeyWord}, builder.Like{"LOWER(attachment.description)", lowerKeyWord})) |
|
|
|
count, err = sess.Table(&Attachment{}).Where(cond).Count(new(AttachmentInfo)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, 0, fmt.Errorf("Count: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
sess.OrderBy("attachment.created_unix DESC") |
|
|
|
attachments := make([]*AttachmentInfo, 0) |
|
|
|
if err := sess.Table(&Attachment{}).Where(cond). |
|
|
|
Find(&attachments); err != nil { |
|
|
|
return nil, 0, fmt.Errorf("Find: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
if opts.NeedRepoInfo { |
|
|
|
for _, attachment := range attachments { |
|
|
|
dataset, err := GetDatasetByID(attachment.DatasetID) |
|
|
|
if err != nil { |
|
|
|
return nil, 0, fmt.Errorf("GetDatasetByID failed error: %v", err) |
|
|
|
} |
|
|
|
attachment.Recommend = dataset.Recommend |
|
|
|
repo, err := GetRepositoryByID(dataset.RepoID) |
|
|
|
if err == nil { |
|
|
|
attachment.Repo = repo |
|
|
|
} else { |
|
|
|
return nil, 0, fmt.Errorf("GetRepositoryByID failed error: %v", err) |
|
|
|
} |
|
|
|
user, err := GetUserByID(attachment.UploaderID) |
|
|
|
if err == nil { |
|
|
|
attachment.RelAvatarLink = user.RelAvatarLink() |
|
|
|
attachment.UserName = user.Name |
|
|
|
} else { |
|
|
|
return nil, 0, fmt.Errorf("GetUserByID failed error: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return attachments, count, nil |
|
|
|
} |