More changes to uploads:
- Have got upload images appearing in the post list - Allowed for deleting uploads - Allowed for seeing the upload progress - Fixed the setting of upload properties like the MIME type - Removed the stripe exif logic with just re-encoding PNGs and JPEGs by loading them and saving them
This commit is contained in:
parent
d0cebe6564
commit
199ff9feb9
21 changed files with 471 additions and 65 deletions
|
|
@ -39,6 +39,24 @@ func (s *Service) FetchUpload(ctx context.Context, uploadID int64) (res UploadWi
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) DeleteUpload(ctx context.Context, uploadID int64) error {
|
||||
site, _, err := s.fetchSiteAndUser(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
upload, err := s.db.SelectUploadByID(ctx, uploadID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.up.DeleteUpload(site, upload); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.db.DeleteUpload(ctx, uploadID)
|
||||
}
|
||||
|
||||
func (s *Service) renderCopyTemplate(upload models.Upload) string {
|
||||
var sb strings.Builder
|
||||
|
||||
|
|
@ -93,3 +111,25 @@ func (s *Service) OpenUpload(ctx context.Context, id int64) (models.Upload, func
|
|||
return rw, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) OpenUploadFromSlug(ctx context.Context, slug string) (models.Upload, func() (io.ReadCloser, error), error) {
|
||||
site, _, err := s.fetchSiteAndUser(ctx)
|
||||
if err != nil {
|
||||
return models.Upload{}, nil, err
|
||||
}
|
||||
|
||||
upload, err := s.db.SelectUploadBySiteIDAndSlug(ctx, site.ID, slug)
|
||||
if err != nil {
|
||||
return models.Upload{}, nil, err
|
||||
} else if upload.SiteID != site.ID {
|
||||
return models.Upload{}, nil, models.NotFoundError
|
||||
}
|
||||
|
||||
return upload, func() (io.ReadCloser, error) {
|
||||
rw, err := s.up.OpenUpload(site, upload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rw, nil
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import (
|
|||
type NewPendingRequest struct {
|
||||
FileSize int64 `json:"size"`
|
||||
Filename string `json:"name"`
|
||||
MIMEType string `json:"type"`
|
||||
MIMEType string `json:"mime"`
|
||||
}
|
||||
|
||||
func (s *Service) NewPending(ctx context.Context, req NewPendingRequest) (models.PendingUpload, error) {
|
||||
|
|
@ -126,7 +126,7 @@ func (s *Service) FinalizePending(ctx context.Context, pendingGUID string, expec
|
|||
if err := s.up.AdoptFile(site, newUpload, pendingDataFilename); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.db.DeletePendingUpload(ctx, newUpload.GUID); err != nil {
|
||||
if err := s.db.DeletePendingUpload(ctx, pendingGUID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.up.StripeEXIFData(site, newUpload); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue