@@ -29,9 +29,9 @@ type FileMetadata struct {
2929
3030// InsertMetadata creates a new metadata entry in the db and returns a unique ID for
3131// that entry.
32- func InsertMetadata (chunks int , name string , plaintext bool ) (string , error ) {
32+ func InsertMetadata (chunks int , ownerID , name string , textOnly bool ) (string , error ) {
3333 prefix := constants .FileIDPrefix
34- if plaintext {
34+ if textOnly {
3535 prefix = constants .PlaintextIDPrefix
3636 }
3737
@@ -43,9 +43,9 @@ func InsertMetadata(chunks int, name string, plaintext bool) (string, error) {
4343 }
4444
4545 s := `INSERT INTO metadata
46- (id, chunks, filename, b2_id, length)
47- VALUES ($1, $2, $3, $4, $5)`
48- _ , err := db .Exec (s , id , chunks , name , "" , - 1 )
46+ (id, chunks, filename, b2_id, length, owner_id, modified )
47+ VALUES ($1, $2, $3, $4, $5, $6, $7 )`
48+ _ , err := db .Exec (s , id , chunks , name , "" , - 1 , ownerID , time . Now (). UTC () )
4949 if err != nil {
5050 panic (err )
5151 }
@@ -70,7 +70,7 @@ func MetadataIDExists(id string) bool {
7070}
7171
7272func RetrieveMetadata (id string ) (FileMetadata , error ) {
73- s := `SELECT m.* , e.downloads, e.date
73+ s := `SELECT m.id, m.chunks, m.filename, m.b2_id, m.length , e.downloads, e.date
7474 FROM metadata m
7575 JOIN expiry e on m.id = e.id
7676 WHERE m.id = $1`
@@ -146,3 +146,65 @@ func DeleteMetadata(id string) bool {
146146
147147 return true
148148}
149+
150+ func AdminRetrieveSendMetadata (fileID string ) (shared.AdminFileInfoResponse , error ) {
151+ var (
152+ id string
153+ name string
154+ length int64
155+ ownerID string
156+ modified time.Time
157+ )
158+
159+ s := `SELECT id, filename, length, owner_id, modified FROM metadata WHERE id=$1`
160+ err := db .QueryRow (s , fileID ).Scan (& id , & name , & length , & ownerID , & modified )
161+ return shared.AdminFileInfoResponse {
162+ ID : id ,
163+ BucketName : name ,
164+ Size : shared .ReadableFileSize (length ),
165+ OwnerID : ownerID ,
166+ Modified : modified ,
167+
168+ RawSize : length ,
169+ }, err
170+ }
171+
172+ func AdminFetchSentFiles (userID string ) ([]shared.AdminFileInfoResponse , error ) {
173+ result := []shared.AdminFileInfoResponse {}
174+
175+ s := `SELECT id, filename, length, owner_id, modified
176+ FROM metadata
177+ WHERE owner_id=$1`
178+
179+ rows , err := db .Query (s , userID )
180+ if err != nil {
181+ return result , err
182+ }
183+
184+ defer rows .Close ()
185+ for rows .Next () {
186+ var (
187+ id string
188+ filename string
189+ length int64
190+ ownerID string
191+ modified time.Time
192+ )
193+
194+ err = rows .Scan (& id , & filename , & length , & ownerID , & modified )
195+ if err != nil {
196+ return result , err
197+ }
198+
199+ result = append (result , shared.AdminFileInfoResponse {
200+ ID : id ,
201+ BucketName : filename ,
202+ Size : shared .ReadableFileSize (length ),
203+ OwnerID : ownerID ,
204+ Modified : modified ,
205+ RawSize : length ,
206+ })
207+ }
208+
209+ return result , nil
210+ }
0 commit comments