mirror of https://github.com/Xhofe/alist
🎇 finish MediaTrack upload
parent
f0d9a452bb
commit
fc48f29575
|
@ -1,6 +1,9 @@
|
||||||
package mediatrack
|
package mediatrack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
|
@ -11,8 +14,10 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -226,11 +231,14 @@ func (driver MediaTrack) Delete(path string, account *model.Account) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver MediaTrack) Upload(file *model.FileStream, account *model.Account) error {
|
func (driver MediaTrack) Upload(file *model.FileStream, account *model.Account) error {
|
||||||
|
if file == nil {
|
||||||
|
return base.ErrEmptyFile
|
||||||
|
}
|
||||||
parentFile, err := driver.File(file.ParentPath, account)
|
parentFile, err := driver.File(file.ParentPath, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
src := "assets/56461b45-6d08-40a0-bfbf-0a47689bffaa" // random?
|
src := "assets/" + uuid.New().String()
|
||||||
var resp UploadResp
|
var resp UploadResp
|
||||||
_, err = driver.Request("https://jayce.api.mediatrack.cn/v3/storage/tokens/asset", base.Get, nil, map[string]string{
|
_, err = driver.Request("https://jayce.api.mediatrack.cn/v3/storage/tokens/asset", base.Get, nil, map[string]string{
|
||||||
"src": src,
|
"src": src,
|
||||||
|
@ -248,21 +256,29 @@ func (driver MediaTrack) Upload(file *model.FileStream, account *model.Account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
var buf bytes.Buffer
|
||||||
|
read := io.TeeReader(file, &buf)
|
||||||
uploader := s3manager.NewUploader(s)
|
uploader := s3manager.NewUploader(s)
|
||||||
input := &s3manager.UploadInput{
|
input := &s3manager.UploadInput{
|
||||||
Bucket: &resp.Data.Bucket,
|
Bucket: &resp.Data.Bucket,
|
||||||
Key: &resp.Data.Object,
|
Key: &resp.Data.Object,
|
||||||
Body: file,
|
Body: read,
|
||||||
}
|
}
|
||||||
_, err = uploader.Upload(input)
|
_, err = uploader.Upload(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
url := fmt.Sprintf("https://jayce.api.mediatrack.cn/v3/assets/%s/children", parentFile.Id)
|
url := fmt.Sprintf("https://jayce.api.mediatrack.cn/v3/assets/%s/children", parentFile.Id)
|
||||||
|
h := md5.New()
|
||||||
|
_, err = io.Copy(h, &buf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
hash := hex.EncodeToString(h.Sum(nil))
|
||||||
data := base.Json{
|
data := base.Json{
|
||||||
"category": 10,
|
"category": 0,
|
||||||
"description": file.GetFileName(),
|
"description": file.GetFileName(),
|
||||||
"hash": "c459fda4d79554d692555932a5d5e6c1",
|
"hash": hash,
|
||||||
"mime": file.MIMEType,
|
"mime": file.MIMEType,
|
||||||
"size": file.GetSize(),
|
"size": file.GetSize(),
|
||||||
"src": src,
|
"src": src,
|
||||||
|
|
Loading…
Reference in New Issue