🚀 Fix everything and ready to launch!
This commit is contained in:
parent
82cb45ec53
commit
8f08d85fb1
@ -5,15 +5,6 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":recycle: Moved onto dealer">
|
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":recycle: Moved onto dealer">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/gap/client.go" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/gap/server.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/gap/server.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/server/exts/auth.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/exts/auth.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/auth.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/auth.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/jwt.go" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/main.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/settings.toml" beforeDir="false" afterPath="$PROJECT_DIR$/settings.toml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/settings.toml" beforeDir="false" afterPath="$PROJECT_DIR$/settings.toml" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
@ -54,7 +45,7 @@
|
|||||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||||
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
||||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||||
"git-widget-placeholder": "refactor/dealer",
|
"git-widget-placeholder": "features/calc-in-backend",
|
||||||
"go.import.settings.migrated": "true",
|
"go.import.settings.migrated": "true",
|
||||||
"go.sdk.automatically.set": "true",
|
"go.sdk.automatically.set": "true",
|
||||||
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hydrogen/Paperclip/pkg/internal/grpc",
|
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hydrogen/Paperclip/pkg/internal/grpc",
|
||||||
|
@ -96,6 +96,7 @@ func createAttachment(c *fiber.Ctx) error {
|
|||||||
_ = jsoniter.UnmarshalFromString(c.FormValue("metadata"), &usermeta)
|
_ = jsoniter.UnmarshalFromString(c.FormValue("metadata"), &usermeta)
|
||||||
|
|
||||||
tx := database.C.Begin()
|
tx := database.C.Begin()
|
||||||
|
|
||||||
metadata, err := services.NewAttachmentMetadata(tx, user, file, models.Attachment{
|
metadata, err := services.NewAttachmentMetadata(tx, user, file, models.Attachment{
|
||||||
Usage: usage,
|
Usage: usage,
|
||||||
Alternative: c.FormValue("alt"),
|
Alternative: c.FormValue("alt"),
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
|
||||||
@ -30,8 +31,11 @@ func PublishAnalyzeTask(file models.Attachment) {
|
|||||||
func StartConsumeAnalyzeTask() {
|
func StartConsumeAnalyzeTask() {
|
||||||
for {
|
for {
|
||||||
task := <-fileAnalyzeQueue
|
task := <-fileAnalyzeQueue
|
||||||
|
start := time.Now()
|
||||||
if err := AnalyzeAttachment(task); err != nil {
|
if err := AnalyzeAttachment(task); err != nil {
|
||||||
log.Error().Err(err).Any("task", task).Msg("A file analyze task failed...")
|
log.Error().Err(err).Any("task", task).Msg("A file analyze task failed...")
|
||||||
|
} else {
|
||||||
|
log.Info().Dur("elapsed", time.Since(start)).Any("task", task).Msg("A file analyze task was completed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,8 +52,8 @@ func AnalyzeAttachment(file models.Attachment) error {
|
|||||||
_ = jsoniter.Unmarshal(rawDest, &dest)
|
_ = jsoniter.Unmarshal(rawDest, &dest)
|
||||||
|
|
||||||
dst := filepath.Join(dest.Path, file.Uuid)
|
dst := filepath.Join(dest.Path, file.Uuid)
|
||||||
if _, err := os.Stat(dst); !os.IsExist(err) {
|
if _, err := os.Stat(dst); os.IsNotExist(err) {
|
||||||
return fmt.Errorf("attachment doesn't exists in temporary storage")
|
return fmt.Errorf("attachment doesn't exists in temporary storage: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if t := strings.SplitN(file.MimeType, "/", 2)[0]; t == "image" {
|
if t := strings.SplitN(file.MimeType, "/", 2)[0]; t == "image" {
|
||||||
@ -85,7 +89,7 @@ func AnalyzeAttachment(file models.Attachment) error {
|
|||||||
if linked && err != nil {
|
if linked && err != nil {
|
||||||
return fmt.Errorf("unable to link file record: %v", err)
|
return fmt.Errorf("unable to link file record: %v", err)
|
||||||
} else if !linked {
|
} else if !linked {
|
||||||
if err := tx.Save(&file); err != nil {
|
if err := tx.Save(&file).Error; err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return fmt.Errorf("unable to save file record: %v", err)
|
return fmt.Errorf("unable to save file record: %v", err)
|
||||||
}
|
}
|
||||||
@ -116,13 +120,12 @@ func HashAttachment(file models.Attachment) (hash string, err error) {
|
|||||||
_ = jsoniter.Unmarshal(rawDest, &dest)
|
_ = jsoniter.Unmarshal(rawDest, &dest)
|
||||||
|
|
||||||
dst := filepath.Join(dest.Path, file.Uuid)
|
dst := filepath.Join(dest.Path, file.Uuid)
|
||||||
if _, err = os.Stat(dst); !os.IsExist(err) {
|
if _, err = os.Stat(dst); os.IsNotExist(err) {
|
||||||
err = fmt.Errorf("attachment doesn't exists in temporary storage")
|
err = fmt.Errorf("attachment doesn't exists in temporary storage: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var in *os.File
|
var in *os.File
|
||||||
in, err = os.Open("file.txt")
|
in, err = os.Open(dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("unable to open file: %v", err)
|
err = fmt.Errorf("unable to open file: %v", err)
|
||||||
return
|
return
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
@ -23,8 +24,11 @@ func PublishDeleteFileTask(file models.Attachment) {
|
|||||||
func StartConsumeDeletionTask() {
|
func StartConsumeDeletionTask() {
|
||||||
for {
|
for {
|
||||||
task := <-fileDeletionQueue
|
task := <-fileDeletionQueue
|
||||||
|
start := time.Now()
|
||||||
if err := DeleteFile(task); err != nil {
|
if err := DeleteFile(task); err != nil {
|
||||||
log.Error().Err(err).Any("task", task).Msg("A file deletion task failed...")
|
log.Error().Err(err).Any("task", task).Msg("A file deletion task failed...")
|
||||||
|
} else {
|
||||||
|
log.Info().Dur("elapsed", time.Since(start)).Any("task", task).Msg("A file deletion task was completed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,17 +53,19 @@ func ReUploadFileToPermanent(meta models.Attachment) error {
|
|||||||
prevRawDest, _ := jsoniter.Marshal(prevDestMap)
|
prevRawDest, _ := jsoniter.Marshal(prevDestMap)
|
||||||
_ = jsoniter.Unmarshal(prevRawDest, &prevDest)
|
_ = jsoniter.Unmarshal(prevRawDest, &prevDest)
|
||||||
|
|
||||||
in, err := os.Open(filepath.Join(prevDest.Path, meta.Uuid))
|
inDst := filepath.Join(prevDest.Path, meta.Uuid)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to open file in temporary storage: %v", err)
|
|
||||||
}
|
|
||||||
defer in.Close()
|
|
||||||
|
|
||||||
switch dest.Type {
|
switch dest.Type {
|
||||||
case models.DestinationTypeLocal:
|
case models.DestinationTypeLocal:
|
||||||
var destConfigured models.LocalDestination
|
var destConfigured models.LocalDestination
|
||||||
_ = jsoniter.Unmarshal(rawDest, &destConfigured)
|
_ = jsoniter.Unmarshal(rawDest, &destConfigured)
|
||||||
|
|
||||||
|
in, err := os.Open(inDst)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to open file in temporary storage: %v", err)
|
||||||
|
}
|
||||||
|
defer in.Close()
|
||||||
|
|
||||||
out, err := os.Create(filepath.Join(destConfigured.Path, meta.Uuid))
|
out, err := os.Create(filepath.Join(destConfigured.Path, meta.Uuid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to open dest file: %v", err)
|
return fmt.Errorf("unable to open dest file: %v", err)
|
||||||
@ -79,11 +81,6 @@ func ReUploadFileToPermanent(meta models.Attachment) error {
|
|||||||
var destConfigured models.S3Destination
|
var destConfigured models.S3Destination
|
||||||
_ = jsoniter.Unmarshal(rawDest, &destConfigured)
|
_ = jsoniter.Unmarshal(rawDest, &destConfigured)
|
||||||
|
|
||||||
buffer := bytes.NewBuffer(nil)
|
|
||||||
if _, err := io.Copy(buffer, in); err != nil {
|
|
||||||
return fmt.Errorf("create io reader for upload file: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := minio.New(destConfigured.Endpoint, &minio.Options{
|
client, err := minio.New(destConfigured.Endpoint, &minio.Options{
|
||||||
Creds: credentials.NewStaticV4(destConfigured.SecretID, destConfigured.SecretKey, ""),
|
Creds: credentials.NewStaticV4(destConfigured.SecretID, destConfigured.SecretKey, ""),
|
||||||
Secure: destConfigured.EnableSSL,
|
Secure: destConfigured.EnableSSL,
|
||||||
@ -92,8 +89,10 @@ func ReUploadFileToPermanent(meta models.Attachment) error {
|
|||||||
return fmt.Errorf("unable to configure s3 client: %v", err)
|
return fmt.Errorf("unable to configure s3 client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.PutObject(context.Background(), destConfigured.Bucket, filepath.Join(destConfigured.Path, meta.Uuid), buffer, -1, minio.PutObjectOptions{
|
_, err = client.FPutObject(context.Background(), destConfigured.Bucket, filepath.Join(destConfigured.Path, meta.Uuid), inDst, minio.PutObjectOptions{
|
||||||
ContentType: meta.MimeType,
|
ContentType: meta.MimeType,
|
||||||
|
SendContentMd5: false,
|
||||||
|
DisableContentSha256: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to upload file to s3: %v", err)
|
return fmt.Errorf("unable to upload file to s3: %v", err)
|
||||||
@ -128,8 +127,10 @@ func UploadFileToS3(config models.S3Destination, file *multipart.FileHeader, met
|
|||||||
return fmt.Errorf("unable to configure s3 client: %v", err)
|
return fmt.Errorf("unable to configure s3 client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.PutObject(context.Background(), config.Bucket, filepath.Join(config.Path, meta.Uuid), buffer, -1, minio.PutObjectOptions{
|
_, err = client.PutObject(context.Background(), config.Bucket, filepath.Join(config.Path, meta.Uuid), buffer, file.Size, minio.PutObjectOptions{
|
||||||
ContentType: meta.MimeType,
|
ContentType: meta.MimeType,
|
||||||
|
SendContentMd5: false,
|
||||||
|
DisableContentSha256: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to upload file to s3: %v", err)
|
return fmt.Errorf("unable to upload file to s3: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user