Skip to content

Commit

Permalink
fix download error
Browse files Browse the repository at this point in the history
  • Loading branch information
dunkbing committed Mar 5, 2024
1 parent ad6582c commit 3b1de65
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions converter/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ func isImage(mimeType string) bool {

type handler struct {
fileManager *image.FileManager
config *config.Config
}

func New() *handler {
c := config.GetConfig()
return &handler{
fileManager: image.NewFileManager(),
config: c,
}
}

Expand All @@ -71,7 +74,6 @@ func (h *handler) Upload(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Invalid file format. Only images are allowed.", http.StatusBadRequest)
return
}
fmt.Println("content type", mimeType, header.Filename)
fileType, _ := image.GetFileType(mimeType)
filename := filepath.Base(header.Filename)
filename = strings.ReplaceAll(filename, " ", "_")
Expand All @@ -81,8 +83,7 @@ func (h *handler) Upload(w http.ResponseWriter, r *http.Request) {

ext = fmt.Sprintf(".%s", fileType)

c := config.GetConfig()
dest := filepath.Join(c.App.InDir, filename)
dest := filepath.Join(h.config.App.InDir, filename)
slog.Info("Upload", "dest", dest)
err = os.WriteFile(dest, data, 0644)
if err != nil {
Expand Down Expand Up @@ -167,7 +168,7 @@ func (h *handler) ServeImg(w http.ResponseWriter, r *http.Request) {
return
}

filePath := filepath.Join("output", fileName)
filePath := filepath.Join(h.config.App.OutDir, fileName)

_, err := os.Stat(filePath)
if os.IsNotExist(err) {
Expand Down

0 comments on commit 3b1de65

Please sign in to comment.