forked from jason/cpolis
Make all files and directories in the config absolute
This commit is contained in:
@ -44,22 +44,15 @@ func UploadDocx(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
docxFilename := fmt.Sprint(uuid.New(), ".docx")
|
||||
absDocxFilepath, err := filepath.Abs("/tmp/" + docxFilename)
|
||||
if err != nil {
|
||||
docxFilepath := filepath.Join(os.TempDir(), fmt.Sprint(uuid.New(), ".docx"))
|
||||
if err = os.WriteFile(docxFilepath, buf.Bytes(), 0644); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer os.Remove(docxFilepath)
|
||||
|
||||
if err = os.WriteFile(absDocxFilepath, buf.Bytes(), 0644); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer os.Remove(absDocxFilepath)
|
||||
|
||||
mdString, err := b.ConvertToMarkdown(c, absDocxFilepath)
|
||||
mdString, err := b.ConvertToMarkdown(c, docxFilepath)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -67,15 +60,8 @@ func UploadDocx(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||
}
|
||||
|
||||
uuidName := uuid.New()
|
||||
mdFilename := fmt.Sprint(uuidName, ".md")
|
||||
absMdFilepath, err := filepath.Abs(c.ArticleDir + "/" + mdFilename)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.WriteFile(absMdFilepath, mdString, 0644); err != nil {
|
||||
mdFilepath := filepath.Join(c.ArticleDir, fmt.Sprint(uuidName, ".md"))
|
||||
if err = os.WriteFile(mdFilepath, mdString, 0644); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -44,17 +44,11 @@ func UploadPDF(c *b.Config, s map[string]*Session) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
oldFilename := header.Filename
|
||||
oldFilename = strings.Join(strings.Split(oldFilename, ".")[:len(oldFilename)-1], ".")
|
||||
oldFilename := strings.Join(strings.Split(header.Filename, ".")[:len(header.Filename)-1], ".")
|
||||
filename := fmt.Sprint(oldFilename, ".", uuid.New(), ".pdf")
|
||||
absFilepath, err := filepath.Abs(c.PDFDir + "/" + filename)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
filepath := filepath.Join(c.PDFDir, filename)
|
||||
|
||||
if err = b.WriteFile(absFilepath, file); err != nil {
|
||||
if err = b.WriteFile(filepath, file); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
Reference in New Issue
Block a user