Skip to content

Upgrade to new-api; add support for embedded audio #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ type PreFinishCommand struct {
RejectOnNoneZeroExit bool
}

type FileTypes struct {
Allowed []string
Disallowed []string
}

type Config struct {
Server struct {
ListenAddress string
Expand All @@ -54,6 +59,7 @@ type Config struct {
IdentifiedMaxAge duration
CheckInterval duration
}
FileTypes FileTypes
PreFinishCommands []PreFinishCommand
JwtSecretsByIssuer map[string]string
Loggers []LoggerConfig
Expand Down Expand Up @@ -135,7 +141,7 @@ func CreateMultiLogger(loggerConfigs []LoggerConfig) (*zerolog.Logger, error) {
url := loggerCfg.Output.URL
switch url.Scheme {
case "file":
file, err := os.OpenFile(url.Path + url.Opaque, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0640)
file, err := os.OpenFile(url.Path+url.Opaque, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0640)
if err != nil {
return nil, err
}
Expand Down
8 changes: 8 additions & 0 deletions config/default-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ CheckInterval = "5m"
# "example.com" = "examplesecret"
# "169.254.0.0" = "anothersecret"

[FileTypes]
Allowed = [
# "image/*"
]
Disallowed = [
# "image/*"
]

# PreFinishCommands allows system commands to be run based on minetype once the file is fully uploaded
# but before it is hashed and moved from incomplete so the file can be rejected using RejectOnNoneZeroExit
# %FILE% will be replace with the full path to the file within [Storage.Path]/incomplete/
Expand Down
42 changes: 36 additions & 6 deletions db/db.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package db

import (
"database/sql"
"fmt"
"strings"
"sync"

"github.com/jmoiron/sqlx"

Expand All @@ -15,7 +17,8 @@ type DBConfig struct {
}

type DatabaseConnection struct {
DB *sqlx.DB
DB *sqlx.DB
DBLock sync.RWMutex
DBConfig
}

Expand All @@ -24,7 +27,7 @@ func ConnectToDB(log *zerolog.Logger, dbConfig DBConfig) *DatabaseConnection {
// Add the default connection options if none are given
switch dbConfig.DriverName {
case "sqlite3":
dbConfig.DSN += "?_busy_timeout=5000&cache=shared"
dbConfig.DSN += "?_busy_timeout=5000"
case "mysql":
dbConfig.DSN += "?parseTime=true"
}
Expand All @@ -35,6 +38,10 @@ func ConnectToDB(log *zerolog.Logger, dbConfig DBConfig) *DatabaseConnection {
log.Fatal().Err(err).Msg("Could not open database")
}

// if dbConfig.DriverName == "sqlite3" {
// db.SetMaxOpenConns(1)
// }

// note that we don't do db.SetMaxOpenConns(1), as we don't want to limit
// read concurrency unnecessarily. sqlite will handle write locking on its
// own, even across multiple processes accessing the same database file.
Expand All @@ -44,14 +51,19 @@ func ConnectToDB(log *zerolog.Logger, dbConfig DBConfig) *DatabaseConnection {
// networked filesystem

return &DatabaseConnection{
db,
dbConfig,
DB: db,
DBConfig: dbConfig,
}
}

// UpdateRow wraps db.Exec and ensures that exactly one row was affected
func UpdateRow(db *sqlx.DB, query string, args ...interface{}) (err error) {
res, err := db.Exec(query, args...)
func UpdateRow(DBConn *DatabaseConnection, query string, args ...any) (err error) {
if DBConn.DBConfig.DriverName == "sqlite3" {
DBConn.DBLock.Lock()
defer DBConn.DBLock.Unlock()
}

res, err := DBConn.DB.Exec(query, args...)
if err != nil {
return
}
Expand All @@ -65,3 +77,21 @@ func UpdateRow(db *sqlx.DB, query string, args ...interface{}) (err error) {
}
return
}

func QueryRow(DBConn *DatabaseConnection, query string, args ...any) *sql.Row {
if DBConn.DBConfig.DriverName == "sqlite3" {
DBConn.DBLock.RLock()
defer DBConn.DBLock.RUnlock()
}

return DBConn.DB.QueryRow(query, args...)
}

func Select(DBConn *DatabaseConnection, dest any, query string, args ...any) (err error) {
if DBConn.DBConfig.DriverName == "sqlite3" {
DBConn.DBLock.RLock()
defer DBConn.DBLock.RUnlock()
}

return DBConn.DB.Select(dest, query, args...)
}
7 changes: 3 additions & 4 deletions events/tus-events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (

"github.com/tus/tusd/cmd/tusd/cli/hooks"
"github.com/tus/tusd/pkg/handler"
tusd "github.com/tus/tusd/pkg/handler"
)

// how many events can be unread by a listener before everything starts to block
const bufferSize = 16

type TusEvent struct {
Info tusd.FileInfo
Info handler.FileInfo
Type hooks.HookType
}

Expand All @@ -22,7 +21,7 @@ type TusEventBroadcaster struct {
quitChan chan struct{} // closes to signal quitting
}

func NewTusEventBroadcaster(handler *tusd.UnroutedHandler) *TusEventBroadcaster {
func NewTusEventBroadcaster(handler *handler.UnroutedHandler) *TusEventBroadcaster {
broadcaster := &TusEventBroadcaster{
quitChan: make(chan struct{}),
}
Expand Down Expand Up @@ -58,7 +57,7 @@ func (b *TusEventBroadcaster) Unlisten(listener chan *TusEvent) {
b.listeners = b.listeners[:kept]
}

func (b *TusEventBroadcaster) readLoop(handler *tusd.UnroutedHandler) {
func (b *TusEventBroadcaster) readLoop(handler *handler.UnroutedHandler) {
for {
select {
case info := <-handler.CompleteUploads:
Expand Down
3 changes: 2 additions & 1 deletion expirer/expirer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package expirer
import (
"time"

"github.com/kiwiirc/plugin-fileuploader/db"
"github.com/kiwiirc/plugin-fileuploader/shardedfilestore"
"github.com/rs/zerolog"
)
Expand Down Expand Up @@ -55,7 +56,7 @@ func (expirer *Expirer) gc(t time.Time) {
Msg("Filestore GC tick")

var expiredIds []string
err := expirer.store.DBConn.DB.Select(&expiredIds, `
err := db.Select(expirer.store.DBConn, &expiredIds, `
SELECT id
FROM uploads
WHERE deleted = 0 AND (
Expand Down
36 changes: 0 additions & 36 deletions fileuploader-kiwiirc-plugin/.editorconfig

This file was deleted.

4 changes: 2 additions & 2 deletions fileuploader-kiwiirc-plugin/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dist/
tests/unit/coverage/
/node_modules/
/dist/
Loading