reports!!!! and PoW!!!!!!!
this has taken quite a while (8 ish hours) but reports and proof of work challenges are completely implemented the proof of work challenges are bit iffy and could be gpu accelerated which is bad, so i plan to eventually switch to something memory hard like argon2id references used for pow: https://dev.to/ratmd/simple-proof-of-work-in-javascript-3kgm https://anubis.techaro.lol/docs/design/how-anubis-works https://anubis.techaro.lol/docs/design/why-proof-of-work as well as some other posts or repos found when searching
This commit is contained in:
+8
-5
@@ -30,14 +30,14 @@ type Upload struct {
|
||||
|
||||
type Report struct {
|
||||
ID string `gorm:"column:id;primaryKey"`
|
||||
UploadID string
|
||||
UploadID string `gorm:"column:upload_id;not null;index"`
|
||||
Reason string `gorm:"column:reason;not null"`
|
||||
Upload Upload `gorm:"foreignKey:UploadID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
|
||||
Upload Upload `gorm:"foreignKey:UploadID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
|
||||
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime"`
|
||||
}
|
||||
|
||||
func initDatabase(path string) (*gorm.DB, error) {
|
||||
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{})
|
||||
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{TranslateError: true})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open database: %w", err)
|
||||
}
|
||||
@@ -53,6 +53,9 @@ func initDatabase(path string) (*gorm.DB, error) {
|
||||
walModeErr := fmt.Errorf("enable database WAL: %w", err)
|
||||
return nil, errors.Join(walModeErr, sqlDB.Close())
|
||||
}
|
||||
if err := db.Exec("PRAGMA foreign_keys = ON").Error; err != nil {
|
||||
return nil, fmt.Errorf("enable foreign keys: %w", err)
|
||||
}
|
||||
|
||||
if err := db.AutoMigrate(&Upload{}, &Report{}); err != nil {
|
||||
migrationErr := fmt.Errorf("migrate database: %w", err)
|
||||
@@ -63,11 +66,11 @@ func initDatabase(path string) (*gorm.DB, error) {
|
||||
}
|
||||
|
||||
func insertUpload(db *gorm.DB, upload *Upload) error {
|
||||
return db.Omit("Upload").Create(upload).Error
|
||||
return db.Create(upload).Error
|
||||
}
|
||||
|
||||
func insertReport(db *gorm.DB, report *Report) error {
|
||||
return db.Create(report).Error
|
||||
return db.Omit("Upload").Create(report).Error
|
||||
}
|
||||
|
||||
func getUploadById(db *gorm.DB, id string) (*Upload, error) {
|
||||
|
||||
Reference in New Issue
Block a user