feat: add basic workings
This commit is contained in:
@@ -25,13 +25,13 @@ func BuildFileRecord(r io.Reader, metaName string, contentDirectory string) (Fil
|
||||
return File{}, err
|
||||
}
|
||||
|
||||
safeName := security.GenerateSafeCategoryName(category, ext)
|
||||
safeName := security.GenerateSafeName() + ext
|
||||
destPath := filepath.Join(contentDirectory, safeName)
|
||||
|
||||
f := File{
|
||||
MediaType: category,
|
||||
MetaName: metaName,
|
||||
FileName: safeName,
|
||||
FileID: safeName,
|
||||
FilePath: destPath,
|
||||
Checksum: checksum,
|
||||
}
|
||||
@@ -39,16 +39,21 @@ func BuildFileRecord(r io.Reader, metaName string, contentDirectory string) (Fil
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func BuildKeyRecord(keyHash string, metaName string, expiresAt time.Time) AccessKey {
|
||||
safeName := security.GenerateSafeName()
|
||||
func BuildKeyRecord(keyHash string, metaName string, expiresAt time.Time) (AccessKey, error) {
|
||||
now := time.Now()
|
||||
if expiresAt.Before(now) {
|
||||
return AccessKey{}, fmt.Errorf("key is already expired")
|
||||
}
|
||||
|
||||
safeName := "orbits_" + security.GenerateSafeName()
|
||||
|
||||
k := AccessKey{
|
||||
MetaName: metaName,
|
||||
KeyName: safeName,
|
||||
KeyID: safeName,
|
||||
KeyHash: keyHash,
|
||||
Revoked: false,
|
||||
ExpiresAt: expiresAt,
|
||||
}
|
||||
|
||||
return k
|
||||
return k, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user