Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
hexahigh committed Feb 27, 2024
1 parent e096334 commit 1afcb5c
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ import (
const version = "2.2.0"

var (
dataDir = flag.String("d", "./data", "Folder to store files")
port = flag.Int("p", 8080, "Port to listen on")
compress = flag.Bool("c", false, "Enable compression")
level = flag.Int("l", 3, "Compression level")
dbType = flag.String("db", "sqlite", "Database type (sqlite or mysql)")
dbPass = flag.String("db:pass", "", "Database password (Unused for sqlite)")
dbUser = flag.String("db:user", "root", "Database user (Unused for sqlite)")
dbHost = flag.String("db:host", "localhost:3306", "Database host (Unused for sqlite)")
dbDb = flag.String("db:db", "yapc", "Database name (Unused for sqlite)")
dbFile = flag.String("db:file", "./data/yapc.db", "SQLite database file")
cleanDb = flag.Bool("cleandb", false, "Clean the database")
dataDir = flag.String("d", "./data", "Folder to store files")
port = flag.Int("p", 8080, "Port to listen on")
compress = flag.Bool("c", false, "Enable compression")
level = flag.Int("l", 3, "Compression level")
dbType = flag.String("db", "sqlite", "Database type (sqlite or mysql)")
dbPass = flag.String("db:pass", "", "Database password (Unused for sqlite)")
dbUser = flag.String("db:user", "root", "Database user (Unused for sqlite)")
dbHost = flag.String("db:host", "localhost:3306", "Database host (Unused for sqlite)")
dbDb = flag.String("db:db", "yapc", "Database name (Unused for sqlite)")
dbFile = flag.String("db:file", "./data/yapc.db", "SQLite database file")
fixDb = flag.Bool("fixdb", false, "Fix the database")
fixDb_dry = flag.Bool("fixdb:dry", false, "Dry run fixdb")
)

var downloadSpeeds []float64
Expand Down Expand Up @@ -73,8 +74,8 @@ func main() {
os.Exit(1)
}

if *cleanDb {
dbClean()
if *fixDb {
dbFixer()
}

onStart()
Expand Down Expand Up @@ -663,7 +664,7 @@ func handlePing(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("pong"))
}

func dbClean() {
func dbFixer() {
log.Println("Cleaning database")

log.Println("Looking for missing files...")
Expand Down Expand Up @@ -691,12 +692,13 @@ func dbClean() {
_, err := os.Stat(filePath)
if os.IsNotExist(err) {
// If the file does not exist, delete the entry from the database
_, err := db.Exec("DELETE FROM data WHERE id = ?", id)
if err != nil {
log.Printf("Failed to delete entry with ID %s: %v", id, err)
} else {
log.Printf("Deleted entry with ID %s because the file does not exist", id)
if !*fixDb_dry {
_, err := db.Exec("DELETE FROM data WHERE id = ?", id)
if err != nil {
log.Printf("Failed to delete entry with ID %s: %v", id, err)
}
}
log.Printf("Deleted entry with ID %s because the file does not exist", id)
}
}

Expand Down

0 comments on commit 1afcb5c

Please sign in to comment.