🐛 I am dumb
This commit is contained in:
		
							
								
								
									
										3
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										3
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							@@ -6,7 +6,10 @@
 | 
			
		||||
  <component name="ChangeListManager">
 | 
			
		||||
    <list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Fix uuid duplicate when link exists">
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/pkg/models/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/models/attachments.go" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/pkg/server/attachments_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/attachments_api.go" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/pkg/services/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/services/attachments.go" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/settings.toml" beforeDir="false" afterPath="$PROJECT_DIR$/settings.toml" afterDir="false" />
 | 
			
		||||
    </list>
 | 
			
		||||
    <option name="SHOW_DIALOG" value="false" />
 | 
			
		||||
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ import "gorm.io/datatypes"
 | 
			
		||||
type Attachment struct {
 | 
			
		||||
	BaseModel
 | 
			
		||||
 | 
			
		||||
	Uuid        string `json:"uuid" gorm:"uniqueIndex"`
 | 
			
		||||
	Uuid        string `json:"uuid"`
 | 
			
		||||
	Size        int64  `json:"size"`
 | 
			
		||||
	Name        string `json:"name"`
 | 
			
		||||
	Alternative string `json:"alt"`
 | 
			
		||||
 
 | 
			
		||||
@@ -19,9 +19,9 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func openAttachment(c *fiber.Ctx) error {
 | 
			
		||||
	id := c.Params("id")
 | 
			
		||||
	id, _ := c.ParamsInt("id", 0)
 | 
			
		||||
 | 
			
		||||
	metadata, err := services.GetAttachmentByUUID(id)
 | 
			
		||||
	metadata, err := services.GetAttachmentByID(uint(id))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fiber.NewError(fiber.StatusNotFound)
 | 
			
		||||
	}
 | 
			
		||||
@@ -58,9 +58,9 @@ func openAttachment(c *fiber.Ctx) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getAttachmentMeta(c *fiber.Ctx) error {
 | 
			
		||||
	id := c.Params("id")
 | 
			
		||||
	id, _ := c.ParamsInt("id")
 | 
			
		||||
 | 
			
		||||
	metadata, err := services.GetAttachmentByUUID(id)
 | 
			
		||||
	metadata, err := services.GetAttachmentByID(uint(id))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fiber.NewError(fiber.StatusNotFound)
 | 
			
		||||
	}
 | 
			
		||||
@@ -132,6 +132,7 @@ func createAttachment(c *fiber.Ctx) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func updateAttachmentMeta(c *fiber.Ctx) error {
 | 
			
		||||
	id, _ := c.ParamsInt("id", 0)
 | 
			
		||||
	user := c.Locals("principal").(models.Account)
 | 
			
		||||
 | 
			
		||||
	var data struct {
 | 
			
		||||
@@ -147,9 +148,9 @@ func updateAttachmentMeta(c *fiber.Ctx) error {
 | 
			
		||||
 | 
			
		||||
	var attachment models.Attachment
 | 
			
		||||
	if err := database.C.Where(models.Attachment{
 | 
			
		||||
		Uuid:      c.Params("id"),
 | 
			
		||||
		BaseModel: models.BaseModel{ID: uint(id)},
 | 
			
		||||
		AccountID: user.ID,
 | 
			
		||||
	}).Error; err != nil {
 | 
			
		||||
	}).First(&attachment).Error; err != nil {
 | 
			
		||||
		return fiber.NewError(fiber.StatusBadRequest, err.Error())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -48,9 +48,11 @@ func NewAttachmentMetadata(tx *gorm.DB, user models.Account, file *multipart.Fil
 | 
			
		||||
	exists, pickupErr := GetAttachmentByHash(attachment.HashCode)
 | 
			
		||||
	if pickupErr == nil {
 | 
			
		||||
		linked = true
 | 
			
		||||
		exists.Alternative = attachment.Alternative
 | 
			
		||||
		exists.Usage = attachment.Usage
 | 
			
		||||
		exists.Metadata = attachment.Metadata
 | 
			
		||||
		attachment = exists
 | 
			
		||||
		attachment.ID = 0
 | 
			
		||||
		attachment.Uuid = uuid.NewString()
 | 
			
		||||
		attachment.AccountID = user.ID
 | 
			
		||||
	} else {
 | 
			
		||||
		// Upload the new file
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ preferred_destination = "local"
 | 
			
		||||
accepts_usage = ["p.avatar", "p.banner", "i.attachment", "m.attachment"]
 | 
			
		||||
 | 
			
		||||
[debug]
 | 
			
		||||
database = true
 | 
			
		||||
database = false
 | 
			
		||||
print_routes = false
 | 
			
		||||
 | 
			
		||||
[passport]
 | 
			
		||||
@@ -39,4 +39,4 @@ bucket = "bucket"
 | 
			
		||||
endpoint = "s3.ap-east-1.amazonaws.com"
 | 
			
		||||
secret_id = "secret"
 | 
			
		||||
secret_key = "secret"
 | 
			
		||||
enable_ssl = true
 | 
			
		||||
enable_ssl = true
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user