maintain (go): go format

This commit is contained in:
Mickael Kerjean 2021-08-22 16:45:54 +10:00
parent a0b2ca72ed
commit f7a4e52703
69 changed files with 2317 additions and 3221 deletions

View file

@ -41,6 +41,7 @@ func (d *Driver) Drivers() map[string]IBackend {
}
type Nothing struct{}
func (b Nothing) Init(params map[string]string, app *App) (IBackend, error) {
return &Nothing{}, nil
}

View file

@ -73,10 +73,8 @@ func NewQuickCache(arg ...time.Duration) AppCache {
return c
}
// ============================================================================
type KeyValueStore struct {
cache map[string]interface{}
sync.RWMutex

View file

@ -31,7 +31,6 @@ func init(){
os.MkdirAll(filepath.Join(GetCurrentDir(), TMP_PATH), os.ModePerm)
}
var (
BUILD_REF string
BUILD_DATE string

View file

@ -12,8 +12,8 @@ import (
"hash/fnv"
"io"
"io/ioutil"
mathrand "math/rand"
"math/big"
mathrand "math/rand"
"os"
"runtime"
)

View file

@ -1,8 +1,8 @@
package common
import (
"runtime"
"fmt"
"runtime"
)
func PrintMemUsage() {

View file

@ -3,8 +3,8 @@ package common
import (
"crypto/tls"
"fmt"
"net/http"
"net"
"net/http"
"time"
)
@ -56,9 +56,11 @@ var DefaultTLSConfig = tls.Config{
func NewTransormedTransport(transport http.Transport) http.RoundTripper {
return &TransformedTransport{&transport}
}
type TransformedTransport struct {
Orig http.RoundTripper
}
func (this *TransformedTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Add("User-Agent", USER_AGENT)
return this.Orig.RoundTrip(req)

View file

@ -8,9 +8,11 @@ import (
func NewNilLogger() *slog.Logger {
return slog.New(dummyWriter{}, "", slog.LstdFlags)
}
type dummyWriter struct {
io.Writer
}
func (this dummyWriter) Write(p []byte) (n int, err error) {
return len(p), nil
}

View file

@ -1,12 +1,12 @@
package common
import (
slog "log"
"fmt"
"time"
slog "log"
"os"
"path/filepath"
"strings"
"time"
)
var logfile *os.File

View file

@ -1,9 +1,9 @@
package common
import (
"github.com/gorilla/mux"
"io"
"net/http"
"github.com/gorilla/mux"
)
const (
@ -16,7 +16,6 @@ type Plugin struct {
Enable bool
}
type Register struct{}
type Get struct{}
@ -29,6 +28,7 @@ var Hooks = struct {
}
var process_file_content_before_send []func(io.ReadCloser, *App, *http.ResponseWriter, *http.Request) (io.ReadCloser, error)
func (this Register) ProcessFileContentBeforeSend(fn func(io.ReadCloser, *App, *http.ResponseWriter, *http.Request) (io.ReadCloser, error)) {
process_file_content_before_send = append(process_file_content_before_send, fn)
}
@ -37,6 +37,7 @@ func (this Get) ProcessFileContentBeforeSend() []func(io.ReadCloser, *App, *http
}
var http_endpoint []func(*mux.Router, *App) error
func (this Register) HttpEndpoint(fn func(*mux.Router, *App) error) {
http_endpoint = append(http_endpoint, fn)
}
@ -45,6 +46,7 @@ func (this Get) HttpEndpoint() []func(*mux.Router, *App) error {
}
var starter_process []func(*mux.Router)
func (this Register) Starter(fn func(*mux.Router)) {
starter_process = append(starter_process, fn)
}
@ -52,12 +54,12 @@ func (this Get) Starter() []func(*mux.Router) {
return starter_process
}
/*
* UI Overrides
* They are the means by which server plugin change the frontend behaviors.
*/
var overrides []string
func (this Register) FrontendOverrides(url string) {
overrides = append(overrides, url)
}
@ -66,6 +68,7 @@ func (this Get) FrontendOverrides() []string {
}
var xdg_open []string
func (this Register) XDGOpen(jsString string) {
xdg_open = append(xdg_open, jsString)
}
@ -74,6 +77,7 @@ func (this Get) XDGOpen() []string {
}
const OverrideVideoSourceMapper = "/overrides/video-transcoder.js"
func init() {
Hooks.Register.FrontendOverrides(OverrideVideoSourceMapper)
}

View file

@ -60,7 +60,6 @@ func SendSuccessResultWithEtagAndGzip(res http.ResponseWriter, req *http.Request
res.Write(dataToSend)
}
func SendSuccessResults(res http.ResponseWriter, data interface{}) {
encoder := json.NewEncoder(res)
encoder.SetEscapeHTML(false)

View file

@ -30,7 +30,7 @@ func generateNewCertificate(root *x509.Certificate, key *rsa.PrivateKey) (*x509.
if err != nil {
return nil, nil, err
}
cert, err := x509.ParseCertificate(certDER);
cert, err := x509.ParseCertificate(certDER)
if err != nil {
return nil, nil, err
}

View file

@ -2,8 +2,8 @@ package ssl
import (
. "github.com/mickael-kerjean/filestash/server/common"
"path/filepath"
"os"
"path/filepath"
)
var keyPEMPath string = filepath.Join(GetCurrentDir(), CERT_PATH, "key.pem")

View file

@ -130,15 +130,24 @@ func(s *Share) UnmarshallJSON(b []byte) error {
}
for key, value := range tmp {
switch key {
case "password": s.Password = NewStringpFromInterface(value)
case "users": s.Users = NewStringpFromInterface(value)
case "expire": s.Expire = NewInt64pFromInterface(value)
case "url": s.Url = NewStringpFromInterface(value)
case "can_share": s.CanShare = NewBoolFromInterface(value)
case "can_manage_own": s.CanManageOwn = NewBoolFromInterface(value)
case "can_read": s.CanRead = NewBoolFromInterface(value)
case "can_write": s.CanWrite = NewBoolFromInterface(value)
case "can_upload": s.CanUpload = NewBoolFromInterface(value)
case "password":
s.Password = NewStringpFromInterface(value)
case "users":
s.Users = NewStringpFromInterface(value)
case "expire":
s.Expire = NewInt64pFromInterface(value)
case "url":
s.Url = NewStringpFromInterface(value)
case "can_share":
s.CanShare = NewBoolFromInterface(value)
case "can_manage_own":
s.CanManageOwn = NewBoolFromInterface(value)
case "can_read":
s.CanRead = NewBoolFromInterface(value)
case "can_write":
s.CanWrite = NewBoolFromInterface(value)
case "can_upload":
s.CanUpload = NewBoolFromInterface(value)
}
}
return nil

View file

@ -24,8 +24,10 @@ func NewInt(t int) *int {
func NewBoolFromInterface(val interface{}) bool {
switch val.(type) {
case bool: return val.(bool)
default: return false
case bool:
return val.(bool)
default:
return false
}
}
@ -37,7 +39,8 @@ func NewInt64pFromInterface(val interface{}) *int64 {
case float64:
v := int64(val.(float64))
return &v
default: return nil
default:
return nil
}
}
@ -46,7 +49,8 @@ func NewStringpFromInterface(val interface{}) *string {
case string:
v := val.(string)
return &v
default: return nil
default:
return nil
}
}
@ -55,7 +59,8 @@ func NewStringFromInterface(val interface{}) string {
case string:
v := val.(string)
return v
default: return ""
default:
return ""
}
}

View file

@ -22,7 +22,7 @@ func AdminSessionGet(ctx App, res http.ResponseWriter, req *http.Request) {
return c.Value
}()
str, err := DecryptString(SECRET_KEY_DERIVATE_FOR_ADMIN, obfuscate);
str, err := DecryptString(SECRET_KEY_DERIVATE_FOR_ADMIN, obfuscate)
if err != nil {
SendSuccessResult(res, false)
return

View file

@ -3,9 +3,9 @@ package ctrl
import (
"bytes"
"fmt"
"github.com/gorilla/mux"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/model"
"github.com/gorilla/mux"
"io"
"net/http"
"os"
@ -17,7 +17,6 @@ import (
//go:generate sh -c "go run ../generator/emacs-el.go > export_generated.go && go fmt export_generated.go"
var EmacsElConfig string = ""
func FileExport(ctx App, res http.ResponseWriter, req *http.Request) {
http.SetCookie(res, &http.Cookie{
Name: "download",

View file

@ -151,7 +151,7 @@ func FileCat(ctx App, res http.ResponseWriter, req *http.Request) {
if req.Header.Get("range") != "" {
ctx.Session["_path"] = path
if p := FileCache.Get(ctx.Session); p != nil {
f, err := os.OpenFile(p.(string), os.O_RDONLY, os.ModePerm);
f, err := os.OpenFile(p.(string), os.O_RDONLY, os.ModePerm)
if err == nil {
file = f
if fi, err := f.Stat(); err == nil {
@ -195,7 +195,7 @@ func FileCat(ctx App, res http.ResponseWriter, req *http.Request) {
}
} else {
tmpPath := filepath.Join(GetCurrentDir(), TMP_PATH, "file_"+QuickString(20)+".dat")
f, err := os.OpenFile(tmpPath, os.O_RDWR|os.O_CREATE, os.ModePerm);
f, err := os.OpenFile(tmpPath, os.O_RDWR|os.O_CREATE, os.ModePerm)
if err != nil {
SendErrorResult(res, err)
return

View file

@ -67,7 +67,7 @@ func SessionAuthenticate(ctx App, res http.ResponseWriter, req *http.Request) {
return
}
s, err := json.Marshal(session);
s, err := json.Marshal(session)
if err != nil {
SendErrorResult(res, NewError(err.Error(), 500))
return

View file

@ -103,7 +103,7 @@ func ShareVerifyProof(ctx App, res http.ResponseWriter, req *http.Request) {
// 1) initialise the current context
share_id := mux.Vars(req)["share"]
s, err = model.ShareGet(share_id);
s, err = model.ShareGet(share_id)
if err != nil {
SendErrorResult(res, err)
return
@ -132,7 +132,7 @@ func ShareVerifyProof(ctx App, res http.ResponseWriter, req *http.Request) {
}
// 3) process the proof sent by the user
submittedProof, err = model.ShareProofVerifier(s, submittedProof);
submittedProof, err = model.ShareProofVerifier(s, submittedProof)
if err != nil {
submittedProof.Error = NewString(err.Error())
SendSuccessResult(res, submittedProof)

View file

@ -1,15 +1,15 @@
package ctrl
import (
. "github.com/mickael-kerjean/filestash/server/common"
"fmt"
. "github.com/mickael-kerjean/filestash/server/common"
"io"
"text/template"
"net/http"
URL "net/url"
"os"
"path/filepath"
"strings"
"text/template"
)
func StaticHandler(_path string) func(App, http.ResponseWriter, *http.Request) {
@ -42,7 +42,7 @@ func IndexHandler(_path string) func(App, http.ResponseWriter, *http.Request) {
NotFoundHandler(ctx, res, req)
return
}
ua := req.Header.Get("User-Agent");
ua := req.Header.Get("User-Agent")
if strings.Contains(ua, "MSIE ") || strings.Contains(ua, "Trident/") || strings.Contains(ua, "Edge/") {
// Microsoft is behaving on many occasion differently than Firefox / Chrome.
// I have neither the time / motivation for it to work properly
@ -92,8 +92,8 @@ func AboutHandler(ctx App, res http.ResponseWriter, req *http.Request) {
}
func CustomCssHandler(ctx App, res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/css");
io.WriteString(res, Config.Get("general.custom_css").String());
res.Header().Set("Content-Type", "text/css")
io.WriteString(res, Config.Get("general.custom_css").String())
}
func ServeFile(res http.ResponseWriter, req *http.Request, filePath string) {

View file

@ -48,7 +48,6 @@ func WebdavHandler(ctx App, res http.ResponseWriter, req *http.Request) {
h.ServeHTTP(res, req)
}
/*
* OSX ask for a lot of crap while mounting as a network drive. To avoid wasting resources with such
* an imbecile and considering we can't even see the source code they are running, the best approach we

View file

@ -3,10 +3,10 @@ package middleware
import (
"bytes"
"encoding/json"
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
"time"
"net/http"
"sync"
"time"
)
type Middleware func(func(App, http.ResponseWriter, *http.Request)) func(App, http.ResponseWriter, *http.Request)

View file

@ -5,9 +5,9 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/gorilla/mux"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/model"
"github.com/gorilla/mux"
"net/http"
"regexp"
"strings"
@ -26,13 +26,13 @@ func LoggedInOnly(fn func(App, http.ResponseWriter, *http.Request)) func(ctx App
func AdminOnly(fn func(App, http.ResponseWriter, *http.Request)) func(ctx App, res http.ResponseWriter, req *http.Request) {
return func(ctx App, res http.ResponseWriter, req *http.Request) {
if admin := Config.Get("auth.admin").String(); admin != "" {
c, err := req.Cookie(COOKIE_NAME_ADMIN);
c, err := req.Cookie(COOKIE_NAME_ADMIN)
if err != nil {
SendErrorResult(res, ErrPermissionDenied)
return
}
str, err := DecryptString(SECRET_KEY_DERIVATE_FOR_ADMIN, c.Value);
str, err := DecryptString(SECRET_KEY_DERIVATE_FOR_ADMIN, c.Value)
if err != nil {
SendErrorResult(res, ErrPermissionDenied)
return
@ -93,7 +93,7 @@ func RedirectSharedLoginIfNeeded(fn func(App, http.ResponseWriter, *http.Request
return
}
share, err := _extractShare(req);
share, err := _extractShare(req)
if err != nil || share_id != share.Id {
http.Redirect(res, req, fmt.Sprintf("/s/%s?next=%s", share_id, req.URL.Path), http.StatusTemporaryRedirect)
return

View file

@ -26,7 +26,6 @@ func init() {
Backend.Register("gdrive", GDrive{})
}
func (g GDrive) Init(params map[string]string, app *App) (IBackend, error) {
backend := GDrive{}

View file

@ -152,7 +152,6 @@ func (g Git) LoginForm() Form {
Name: "passphrase",
Type: "text",
Placeholder: "Passphrase",
},
FormElement{
Id: "git_commit",
@ -194,7 +193,6 @@ func (g Git) LoginForm() Form {
}
}
func (g Git) Ls(path string) ([]os.FileInfo, error) {
g.git.refresh()
p, err := g.path(path)

View file

@ -179,7 +179,6 @@ func (b Sftp) LoginForm() Form {
Name: "port",
Type: "number",
Placeholder: "Port",
},
FormElement{
Id: "sftp_passphrase",

View file

@ -34,8 +34,12 @@ func OfficeFormater(r io.ReadCloser) (io.ReadCloser, error) {
content := bytes.NewBuffer([]byte{})
for _, f := range z.File {
shouldExtract := false
if f.Name == "word/document.xml" { shouldExtract = true }
if strings.HasPrefix(f.Name, "ppt/slides/slide") { shouldExtract = true }
if f.Name == "word/document.xml" {
shouldExtract = true
}
if strings.HasPrefix(f.Name, "ppt/slides/slide") {
shouldExtract = true
}
if shouldExtract == false {
continue
@ -76,7 +80,6 @@ func OfficeFormater(r io.ReadCloser) (io.ReadCloser, error) {
return NewReadCloserFromReader(content), nil
}
type WordDoc struct {
Text []byte `xml:",innerxml"`
}

View file

@ -4,8 +4,8 @@ import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
. "github.com/mickael-kerjean/filestash/server/common"
"path/filepath"
"os"
"path/filepath"
"time"
)

View file

@ -26,6 +26,7 @@ const (
PHASE_PAUSE = "PHASE_PAUSE"
MAX_HEAP_SIZE = 100000
)
var (
SEARCH_ENABLE func() bool
SEARCH_TIMEOUT func() time.Duration
@ -171,7 +172,8 @@ func init(){
for {
if SEARCH_ENABLE() == false {
select {
case <- onChange.Listener: startSearch = SEARCH_ENABLE()
case <-onChange.Listener:
startSearch = SEARCH_ENABLE()
}
if startSearch == false {
continue
@ -268,7 +270,6 @@ func(this *SearchProcess) HintLs(app *App, path string) *SearchIndexer {
}
this.mu.RUnlock()
// Having all indexers running in memory could be expensive => instead we're cycling a pool
search_process_max := SEARCH_PROCESS_MAX()
this.mu.Lock()
@ -317,7 +318,6 @@ func(this *SearchProcess) HintFile(app *App, path string) {
this.mu.RUnlock()
}
func (this *SearchProcess) Peek() *SearchIndexer {
if len(this.idx) == 0 {
return nil
@ -370,7 +370,7 @@ func NewSearchIndexer(id string, b IBackend) SearchIndexer {
}
s.DB = db
queryDB := func(sqlQuery string) error {
stmt, err := db.Prepare(sqlQuery);
stmt, err := db.Prepare(sqlQuery)
if err != nil {
Log.Warning("search::initschema prepare schema error(%v)", err)
return err
@ -611,16 +611,26 @@ func(this *SearchIndexer) updateFile(path string, tx *sql.Tx) error {
defer reader.Close()
switch GetMimeType(path) {
case "text/plain": reader, err = formater.TxtFormater(reader)
case "text/org": reader, err = formater.TxtFormater(reader)
case "text/markdown": reader, err = formater.TxtFormater(reader)
case "application/x-form": reader, err = formater.TxtFormater(reader)
case "application/pdf": reader, err = formater.PdfFormater(reader)
case "application/powerpoint": reader, err = formater.OfficeFormater(reader)
case "application/vnd.ms-powerpoint": reader, err = formater.OfficeFormater(reader)
case "application/word": reader, err = formater.OfficeFormater(reader)
case "application/msword": reader, err = formater.OfficeFormater(reader)
default: return nil
case "text/plain":
reader, err = formater.TxtFormater(reader)
case "text/org":
reader, err = formater.TxtFormater(reader)
case "text/markdown":
reader, err = formater.TxtFormater(reader)
case "application/x-form":
reader, err = formater.TxtFormater(reader)
case "application/pdf":
reader, err = formater.PdfFormater(reader)
case "application/powerpoint":
reader, err = formater.OfficeFormater(reader)
case "application/vnd.ms-powerpoint":
reader, err = formater.OfficeFormater(reader)
case "application/word":
reader, err = formater.OfficeFormater(reader)
case "application/msword":
reader, err = formater.OfficeFormater(reader)
default:
return nil
}
if err != nil {
@ -817,6 +827,7 @@ type Document struct {
// https://golang.org/pkg/container/heap/
type HeapDoc []*Document
func (h HeapDoc) Len() int { return len(h) }
func (h HeapDoc) Less(i, j int) bool {
if h[i].Priority != 0 || h[j].Priority != 0 {

View file

@ -1,16 +1,16 @@
package model
import (
. "github.com/mickael-kerjean/filestash/server/common"
"bytes"
"crypto/tls"
"database/sql"
"encoding/json"
"github.com/mattn/go-sqlite3"
. "github.com/mickael-kerjean/filestash/server/common"
"golang.org/x/crypto/bcrypt"
"gopkg.in/gomail.v2"
"net/http"
"html/template"
"net/http"
"strings"
"time"
)
@ -136,7 +136,7 @@ func ShareProofVerifier(s Share, proof Proof) (Proof, error) {
return p, NewError("No password required", 400)
}
v, ok := ShareProofVerifierPassword(*s.Password, proof.Value);
v, ok := ShareProofVerifierPassword(*s.Password, proof.Value)
if ok == false {
time.Sleep(1000 * time.Millisecond)
return p, ErrInvalidPassword
@ -157,7 +157,7 @@ func ShareProofVerifier(s Share, proof Proof) (Proof, error) {
user := v
// prepare the verification code
stmt, err := DB.Prepare("INSERT INTO Verification(key, code) VALUES(?, ?)");
stmt, err := DB.Prepare("INSERT INTO Verification(key, code) VALUES(?, ?)")
if err != nil {
return p, err
}
@ -308,7 +308,7 @@ func ShareProofCalculateRemainings(ref []Proof, mem []Proof) []Proof {
for j := 0; j < len(mem); j++ {
if shareProofAreEquivalent(ref[i], mem[j]) {
keep = false
break;
break
}
}
if keep {
@ -319,7 +319,6 @@ func ShareProofCalculateRemainings(ref []Proof, mem []Proof) []Proof {
return remainingProof
}
func shareProofAreEquivalent(ref Proof, p Proof) bool {
if ref.Key != p.Key {
return false

View file

@ -12,8 +12,8 @@ import (
"fmt"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/net/webdav"
"net/http"
"io"
"net/http"
"os"
"path/filepath"
"strings"
@ -21,6 +21,7 @@ import (
)
const DAVCachePath = "data/cache/webdav/"
var (
cachePath string
webdavCache AppCache
@ -66,7 +67,7 @@ func (this *WebdavFs) OpenFile(ctx context.Context, name string, flag int, perm
cachePath := fmt.Sprintf("%stmp_%s", cachePath, Hash(this.id+name, 20))
fwriteFile := func() *os.File {
if this.req.Method == "PUT" {
f, err := os.OpenFile(cachePath+"_writer", os.O_WRONLY|os.O_CREATE|os.O_EXCL, os.ModePerm);
f, err := os.OpenFile(cachePath+"_writer", os.O_WRONLY|os.O_CREATE|os.O_EXCL, os.ModePerm)
if err != nil {
return nil
}
@ -134,7 +135,6 @@ func (this WebdavFs) fullpath(path string) string {
return p
}
/*
* Implement a webdav.File and os.Stat : https://godoc.org/golang.org/x/net/webdav#File
*/
@ -177,7 +177,7 @@ func (this *WebdavFile) Close() error {
func (this *WebdavFile) Seek(offset int64, whence int) (int64, error) {
if this.fread == nil {
this.fread = this.pull_remote_file();
this.fread = this.pull_remote_file()
if this.fread == nil {
return offset, ErrNotFound
}
@ -264,7 +264,7 @@ func (this *WebdavFile) push_to_remote_if_needed() error {
return nil
}
this.fwrite.Close()
f, err := os.OpenFile(this.cache + "_writer", os.O_RDONLY, os.ModePerm);
f, err := os.OpenFile(this.cache+"_writer", os.O_RDONLY, os.ModePerm)
if err != nil {
return err
}
@ -329,6 +329,7 @@ func (this WebdavFile) ETag(ctx context.Context) (string, error) {
}
var lock webdav.LockSystem
func NewWebdavLock() webdav.LockSystem {
if lock == nil {
lock = webdav.NewMemLS()

View file

@ -1,25 +1,25 @@
package plugin
import (
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_starter_http"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_starter_tor"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_console"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_video_transcoder"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_editor_onlyoffice"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_syncthing"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_image_light"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_ftp"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_backblaze"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_dav"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_webdav"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_dropbox"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_ftp"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_ldap"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_mysql"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_s3"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_ldap"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_dropbox"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_webdav"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_editor_onlyoffice"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_console"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_syncthing"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_image_light"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_starter_http"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_starter_tor"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_video_transcoder"
//_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_samba"
. "github.com/mickael-kerjean/filestash/server/common"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_security_scanner"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_security_svg"
. "github.com/mickael-kerjean/filestash/server/common"
)
func init() {

View file

@ -3,8 +3,8 @@ package plg_backend_backblaze
import (
"bytes"
"crypto/sha1"
"encoding/json"
"encoding/base64"
"encoding/json"
"fmt"
. "github.com/mickael-kerjean/filestash/server/common"
"io"
@ -57,7 +57,7 @@ func (this Backblaze) Init(params map[string]string, app *App) (IBackend, error)
}
// To perform some query, we need to first know things like where we will have to query, get a token, ...
res, err := this.request("GET", "https://api.backblazeb2.com/b2api/v2/b2_authorize_account", nil, nil);
res, err := this.request("GET", "https://api.backblazeb2.com/b2api/v2/b2_authorize_account", nil, nil)
if err != nil {
return nil, err
}
@ -438,8 +438,10 @@ func (this Backblaze) Save(path string, file io.Reader) error {
defer f.Close()
defer os.Remove(backblazeFileDetail.path)
io.Copy(f, file)
if obj, ok := file.(io.Closer); ok { obj.Close() }
s, err := f.Stat();
if obj, ok := file.(io.Closer); ok {
obj.Close()
}
s, err := f.Stat()
if err != nil {
return err
}

View file

@ -536,7 +536,7 @@ func (this Dav) getResources(path string) ([]DavResource, error) {
</D:prop>
</C:calendar-query>`
}
return strings.NewReader(query);
return strings.NewReader(query)
}(),
func(req *http.Request) {
req.Header.Add("Depth", "1")
@ -569,7 +569,7 @@ func (this Dav) getResources(path string) ([]DavResource, error) {
name += ".vcf"
} else if this.which == CALDAV {
strToInt := func(chunk string) int {
ret, _ := strconv.Atoi(chunk);
ret, _ := strconv.Atoi(chunk)
return ret
}
for _, line := range strings.Split(r.Responses[i].Ical, "\n") {

File diff suppressed because it is too large Load diff

View file

@ -10,8 +10,8 @@ import (
"os"
"regexp"
"sort"
"strings"
"strconv"
"strings"
"time"
)
@ -217,7 +217,7 @@ func (this Mysql) Ls(path string) ([]os.FileInfo, error) {
}
return ""
}(),
));
))
if err != nil {
return nil, err
}
@ -421,7 +421,7 @@ func (this Mysql) Cat(path string) (io.ReadCloser, error) {
}
// STEP 3: Send the form back to the user
b, err := Form{Elmnts: forms}.MarshalJSON();
b, err := Form{Elmnts: forms}.MarshalJSON()
if err != nil {
return nil, err
}
@ -540,6 +540,7 @@ type SqlKeyParams struct {
Key string
Value interface{}
}
func (this Mysql) Save(path string, file io.Reader) error {
defer this.db.Close()
location, err := NewDBLocation(path)

View file

@ -244,15 +244,24 @@ func IframeContentHandler(ctx App, res http.ResponseWriter, req *http.Request) {
powerpoint string = "presentation"
)
switch GetMimeType(p) {
case "application/word": return word
case "application/msword": return word
case "application/vnd.oasis.opendocument.text": return word
case "application/vnd.oasis.opendocument.spreadsheet": return excel
case "application/excel": return excel
case "application/vnd.ms-excel": return excel
case "application/powerpoint": return powerpoint
case "application/vnd.ms-powerpoint": return powerpoint
case "application/vnd.oasis.opendocument.presentation": return powerpoint
case "application/word":
return word
case "application/msword":
return word
case "application/vnd.oasis.opendocument.text":
return word
case "application/vnd.oasis.opendocument.spreadsheet":
return excel
case "application/excel":
return excel
case "application/vnd.ms-excel":
return excel
case "application/powerpoint":
return powerpoint
case "application/vnd.ms-powerpoint":
return powerpoint
case "application/vnd.oasis.opendocument.presentation":
return powerpoint
}
return ""
}(path)
@ -383,7 +392,8 @@ func OnlyOfficeEventHandler(res http.ResponseWriter, req *http.Request) {
req.Body.Close()
switch event.Status {
case 0: Log.Warning("[onlyoffice] no document with the key identifier could be found. %+v", event)
case 0:
Log.Warning("[onlyoffice] no document with the key identifier could be found. %+v", event)
case 1:
// document is being edited
case 2:
@ -396,7 +406,7 @@ func OnlyOfficeEventHandler(res http.ResponseWriter, req *http.Request) {
case 5:
Log.Warning("[onlyoffice] undocumented status. %+v", event)
case 6: // document is being edited, but the current document state is saved
saveObject, found := OnlyOfficeCache.Get(event.Key);
saveObject, found := OnlyOfficeCache.Get(event.Key)
if found == false {
res.WriteHeader(http.StatusInternalServerError)
res.Write([]byte(`{"error": 1, "message": "doens't know where to store the given data"}`))
@ -422,8 +432,10 @@ func OnlyOfficeEventHandler(res http.ResponseWriter, req *http.Request) {
return
}
f.Body.Close()
case 7: Log.Warning("[onlyoffice] error has occurred while force saving the document. %+v", event)
default: Log.Warning("[onlyoffice] undocumented status. %+v", event)
case 7:
Log.Warning("[onlyoffice] error has occurred while force saving the document. %+v", event)
default:
Log.Warning("[onlyoffice] undocumented status. %+v", event)
}
res.Write([]byte(`{"error": 0}`))
}

View file

@ -6,6 +6,7 @@ package plg_handler_console
import (
"encoding/base64"
"encoding/json"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
"github.com/kr/pty"
@ -15,11 +16,10 @@ import (
"net/http"
"os"
"os/exec"
"encoding/json"
"unsafe"
"strings"
"syscall"
"time"
"unsafe"
)
var console_enable = func() bool {
@ -145,6 +145,7 @@ var resizeMessage = struct {
X uint16
Y uint16
}{}
func handleSocket(res http.ResponseWriter, req *http.Request) {
conn, err := upgrader.Upgrade(res, req, nil)
if err != nil {
@ -252,7 +253,6 @@ EOF
}
}
func htmlIndex(pathPrefix string) []byte {
return []byte(`<!DOCTYPE html>
<html lang="en">

View file

@ -18,6 +18,7 @@ import (
)
const SYNCTHING_URI = "/admin/syncthing"
func init() {
plugin_enable := Config.Get("features.syncthing.enable").Schema(func(f *FormElement) *FormElement {
if f == nil {

View file

@ -7,8 +7,8 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"strconv"
"strings"
)
const ImageCachePath = "data/cache/image/"

View file

@ -1,12 +1,13 @@
package plg_image_light
// #cgo CFLAGS: -I./deps/src
// #include "libtranscode.h"
import "C"
import (
"context"
"golang.org/x/sync/semaphore"
. "github.com/mickael-kerjean/filestash/server/common"
"golang.org/x/sync/semaphore"
"time"
"unsafe"
)

View file

@ -85,7 +85,6 @@ func init() {
})
}
func ensureAppHasBooted(address string, message string) {
i := 0
for {

View file

@ -80,7 +80,6 @@ func init() {
})
}
func ensureAppHasBooted(address string, message string) {
i := 0
for {

View file

@ -50,9 +50,12 @@ func init() {
onChange := Config.ListenForChange()
for {
select {
case <- onChange.Listener: startTor = enable_tor()
case <-onChange.Listener:
startTor = enable_tor()
}
if startTor == true {
break
}
if startTor == true { break }
}
Config.UnlistenForChange(onChange)
}

View file

@ -229,7 +229,7 @@ func ffprobe(videoPath string) (FFProbeData, error) {
"ffprobe", strings.Split(fmt.Sprintf(
"-v quiet -print_format json -show_format -show_streams %s",
videoPath,
), " ")...
), " ")...,
)
cmd.Stdout = &stream
if err := cmd.Run(); err != nil {