@@ -29,9 +29,9 @@ type FileMetadata struct {
29
29
30
30
// InsertMetadata creates a new metadata entry in the db and returns a unique ID for
31
31
// 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 ) {
33
33
prefix := constants .FileIDPrefix
34
- if plaintext {
34
+ if textOnly {
35
35
prefix = constants .PlaintextIDPrefix
36
36
}
37
37
@@ -43,9 +43,9 @@ func InsertMetadata(chunks int, name string, plaintext bool) (string, error) {
43
43
}
44
44
45
45
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 () )
49
49
if err != nil {
50
50
panic (err )
51
51
}
@@ -70,7 +70,7 @@ func MetadataIDExists(id string) bool {
70
70
}
71
71
72
72
func 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
74
74
FROM metadata m
75
75
JOIN expiry e on m.id = e.id
76
76
WHERE m.id = $1`
@@ -146,3 +146,65 @@ func DeleteMetadata(id string) bool {
146
146
147
147
return true
148
148
}
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