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

View File

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