chore: cleanup code

This commit is contained in:
drosoCode 2023-04-02 19:20:36 +02:00
parent 60ce55b083
commit 7200a1ef62
2 changed files with 22 additions and 19 deletions

View File

@ -84,18 +84,22 @@ export default {
); );
document.head.appendChild(onlyofficeScript); document.head.appendChild(onlyofficeScript);
/*eslint-disable */
onlyofficeScript.onload = () => { onlyofficeScript.onload = () => {
let fileUrl = `${window.location.protocol}//${window.location.host}${baseURL}/api/raw${url.encodePath( let fileUrl = `${window.location.protocol}//${window.location.host}${baseURL}/api/raw${url.encodePath(
this.req.path this.req.path
)}?auth=${this.jwt}`; )}?auth=${this.jwt}`;
let key = Date.parse(this.req.modified).toString() + url.encodePath(this.req.path); // create a key from the last modified timestamp and the reversed file path (most specific part first)
key = key.replaceAll(/[-_.!~[\]*'()/,;:\-%+.]/g, ""); // replace all special characters (only these symbols are supported: 0-9, a-z, A-Z, -._=)
if (key.length > 127) { // and truncate it (max length is 20 characters)
key = key.substring(0, 127); const key = (
} Date.parse(this.req.modified).valueOf()
+ url
.encodePath(this.req.path.split('/').reverse().join(''))
.replaceAll(/[!~[\]*'()/,;:\-%+. ]/g, "")
).substring(0, 20);
/*eslint-disable */
let config = { let config = {
document: { document: {
fileType: this.req.extension.substring(1), fileType: this.req.extension.substring(1),
@ -123,8 +127,8 @@ export default {
} }
}; };
this.editor = new DocsAPI.DocEditor("editor", config); this.editor = new DocsAPI.DocEditor("editor", config);
/*eslint-enable */
}; };
/*eslint-enable */
}, },
methods: { methods: {
back() { back() {

View File

@ -3,7 +3,7 @@ package http
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"io/ioutil" "io"
"net/http" "net/http"
) )
@ -17,15 +17,15 @@ type OnlyOfficeCallback struct {
} }
var onlyofficeCallbackHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { var onlyofficeCallbackHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
body, e1 := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if e1 != nil { if err != nil {
return http.StatusInternalServerError, e1 return http.StatusInternalServerError, err
} }
var data OnlyOfficeCallback var data OnlyOfficeCallback
err1 := json.Unmarshal(body, &data) err = json.Unmarshal(body, &data)
if err1 != nil { if err != nil {
return http.StatusInternalServerError, err1 return http.StatusInternalServerError, err
} }
if data.Status == 2 || data.Status == 6 { if data.Status == 2 || data.Status == 6 {
@ -38,13 +38,13 @@ var onlyofficeCallbackHandler = withUser(func(w http.ResponseWriter, r *http.Req
return http.StatusForbidden, nil return http.StatusForbidden, nil
} }
doc, err2 := http.Get(data.URL) doc, err := http.Get(data.URL)
if err2 != nil { if err != nil {
return http.StatusInternalServerError, err2 return http.StatusInternalServerError, err
} }
defer doc.Body.Close() defer doc.Body.Close()
err := d.RunHook(func() error { err = d.RunHook(func() error {
_, writeErr := writeFile(d.user.Fs, docPath, doc.Body) _, writeErr := writeFile(d.user.Fs, docPath, doc.Body)
if writeErr != nil { if writeErr != nil {
return writeErr return writeErr
@ -53,7 +53,6 @@ var onlyofficeCallbackHandler = withUser(func(w http.ResponseWriter, r *http.Req
}, "save", docPath, "", d.user) }, "save", docPath, "", d.user)
if err != nil { if err != nil {
_ = d.user.Fs.RemoveAll(docPath)
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
} }
} }