-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements an admin UI for instance maintainers to allow content moderation as needed. Basic initial features include: - User lookup - Listing files uploaded by a user - File lookup - File deletion - User deletion Admin declaration is handled with the YEETFILE_INSTANCE_ADMIN environment variable, which can be set to an admin's email or account ID to enable. Additional metadata was added to files uploaded via YF Send, since the same need for moderation applies to those files as well. Currently this is web-only since instance maintainers are mostly using the web interface from what I've gathered, but will still be ported to the CLI app soon.
- Loading branch information
Showing
28 changed files
with
753 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE metadata ADD COLUMN owner_id text DEFAULT ''; | ||
UPDATE metadata SET owner_id = ''; | ||
|
||
ALTER TABLE metadata ADD COLUMN modified TIMESTAMP DEFAULT now(); | ||
UPDATE metadata SET modified = now(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package admin | ||
|
||
import ( | ||
"database/sql" | ||
"log" | ||
"yeetfile/backend/db" | ||
"yeetfile/shared" | ||
) | ||
|
||
func deleteFile(fileID string) error { | ||
metadata, err := db.AdminRetrieveMetadata(fileID) | ||
if err == nil { | ||
// Delete vault file | ||
err = db.AdminDeleteFile(fileID) | ||
if err != nil { | ||
log.Printf("Error deleting file: %v\n", err) | ||
return err | ||
} | ||
|
||
_ = db.UpdateStorageUsed(metadata.OwnerID, -metadata.RawSize) | ||
} else { | ||
// Attempt to delete Send file instead | ||
metadata, err := db.RetrieveMetadata(fileID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
db.DeleteFileByMetadata(metadata) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func fetchFileMetadata(fileID string) (shared.AdminFileInfoResponse, error) { | ||
fileInfo, err := db.AdminRetrieveMetadata(fileID) | ||
if err != nil && err != sql.ErrNoRows { | ||
return shared.AdminFileInfoResponse{}, err | ||
} else if err == nil { | ||
return fileInfo, nil | ||
} | ||
|
||
sendFileInfo, err := db.AdminRetrieveSendMetadata(fileID) | ||
if err != nil && err != sql.ErrNoRows { | ||
return shared.AdminFileInfoResponse{}, err | ||
} else if err == nil { | ||
return sendFileInfo, nil | ||
} | ||
|
||
return shared.AdminFileInfoResponse{}, err | ||
} |
Oops, something went wrong.