mirror of
https://github.com/tgdrive/teldrive.git
synced 2025-01-09 00:29:57 +08:00
remove extra db call in upload
This commit is contained in:
parent
193bcb104f
commit
abb5029472
1 changed files with 3 additions and 16 deletions
|
@ -69,25 +69,12 @@ func (us *UploadService) UploadFile(c *gin.Context) (*schemas.UploadPartOut, *ty
|
|||
|
||||
uploadId := c.Param("id")
|
||||
|
||||
var uploadPart []models.Upload
|
||||
|
||||
us.Db.Model(&models.Upload{}).Where("upload_id = ?", uploadId).Where("part_no = ?", uploadQuery.PartNo).
|
||||
Where("user_id = ?", userId).
|
||||
Find(&uploadPart)
|
||||
|
||||
if len(uploadPart) == 1 {
|
||||
out := mapper.MapUploadSchema(&uploadPart[0])
|
||||
return out, nil
|
||||
}
|
||||
|
||||
file := c.Request.Body
|
||||
|
||||
fileSize := c.Request.ContentLength
|
||||
|
||||
fileName := uploadQuery.Filename
|
||||
|
||||
var msgId int
|
||||
|
||||
tokens, err := GetBotsToken(c, userId)
|
||||
|
||||
if err != nil {
|
||||
|
@ -156,16 +143,16 @@ func (us *UploadService) UploadFile(c *gin.Context) (*schemas.UploadPartOut, *ty
|
|||
|
||||
updates := res.(*tg.Updates)
|
||||
|
||||
msgId = updates.Updates[0].(*tg.UpdateMessageID).ID
|
||||
message, ok := updates.Updates[1].(*tg.UpdateNewChannelMessage).Message.(*tg.Message)
|
||||
|
||||
if msgId == 0 {
|
||||
if !ok {
|
||||
return errors.New("failed to upload part")
|
||||
}
|
||||
|
||||
partUpload := &models.Upload{
|
||||
Name: fileName,
|
||||
UploadId: uploadId,
|
||||
PartId: msgId,
|
||||
PartId: message.ID,
|
||||
ChannelID: channelId,
|
||||
Size: fileSize,
|
||||
PartNo: uploadQuery.PartNo,
|
||||
|
|
Loading…
Reference in a new issue