mirror of https://github.com/IoTcat/auxpi.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
63 lines
1.5 KiB
// Copyright (c) 2019 aimerforreimu. All Rights Reserved. |
|
// Use of this source code is governed by a BSD-style |
|
// license that can be found in the LICENSE file. |
|
// |
|
// GNU GENERAL PUBLIC LICENSE |
|
// Version 3, 29 June 2007 |
|
// |
|
// Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> |
|
// Everyone is permitted to copy and distribute verbatim copies |
|
// of this license document, but changing it is not allowed. |
|
// |
|
// repo: https://github.com/aimerforreimu/auxpi |
|
|
|
package server |
|
|
|
import ( |
|
"github.com/auxpi/auxpiAll" |
|
"github.com/auxpi/tools" |
|
) |
|
|
|
type JueJin struct { |
|
FileLimit []string |
|
MaxSize int |
|
} |
|
|
|
func (s *JueJin) Upload(image *ImageParam) (ImageReturn, error) { |
|
url := "https://cdn-ms.juejin.im/v1/upload?bucket=gold-user-assets" |
|
|
|
file := &auxpi.FormFile{ |
|
Name: image.Name, |
|
Key: "file", |
|
Value: *image.Content, |
|
Type: image.Type, |
|
} |
|
var header map[string]string |
|
data := tools.FormPost(file, url, header) |
|
j := auxpi.JueJinResp{} |
|
err := j.UnmarshalJSON([]byte(data)) |
|
if err != nil { |
|
return ImageReturn{}, err |
|
} |
|
return ImageReturn{ |
|
Url: j.D.URL.HTTPS, |
|
ID: 10, |
|
}, nil |
|
} |
|
|
|
func (s *JueJin) UploadToJueJin(img []byte, imgInfo string, imgType string) string { |
|
url := "https://cdn-ms.juejin.im/v1/upload?bucket=gold-user-assets" |
|
name := tools.GetFileNameByMimeType(imgInfo) |
|
|
|
file := &auxpi.FormFile{ |
|
Name: name, |
|
Key: "file", |
|
Value: img, |
|
Type: imgType, |
|
} |
|
var header map[string]string |
|
data := tools.FormPost(file, url, header) |
|
j := auxpi.JueJinResp{} |
|
j.UnmarshalJSON([]byte(data)) |
|
return j.D.URL.HTTPS |
|
}
|
|
|