🗑️ Remove the unused reference system
This commit is contained in:
@@ -24,7 +24,6 @@ public class AccountCurrentController(
|
||||
AccountEventService events,
|
||||
AuthService auth,
|
||||
FileService.FileServiceClient files,
|
||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
||||
Credit.SocialCreditService creditService
|
||||
) : ControllerBase
|
||||
{
|
||||
@@ -122,36 +121,12 @@ public class AccountCurrentController(
|
||||
if (request.PictureId is not null)
|
||||
{
|
||||
var file = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId });
|
||||
if (profile.Picture is not null)
|
||||
await fileRefs.DeleteResourceReferencesAsync(
|
||||
new DeleteResourceReferencesRequest { ResourceId = profile.ResourceIdentifier }
|
||||
);
|
||||
await fileRefs.CreateReferenceAsync(
|
||||
new CreateReferenceRequest
|
||||
{
|
||||
ResourceId = profile.ResourceIdentifier,
|
||||
FileId = request.PictureId,
|
||||
Usage = "profile.picture"
|
||||
}
|
||||
);
|
||||
profile.Picture = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||
}
|
||||
|
||||
if (request.BackgroundId is not null)
|
||||
{
|
||||
var file = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId });
|
||||
if (profile.Background is not null)
|
||||
await fileRefs.DeleteResourceReferencesAsync(
|
||||
new DeleteResourceReferencesRequest { ResourceId = profile.ResourceIdentifier }
|
||||
);
|
||||
await fileRefs.CreateReferenceAsync(
|
||||
new CreateReferenceRequest
|
||||
{
|
||||
ResourceId = profile.ResourceIdentifier,
|
||||
FileId = request.BackgroundId,
|
||||
Usage = "profile.background"
|
||||
}
|
||||
);
|
||||
profile.Background = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ public class AccountService(
|
||||
AppDatabase db,
|
||||
MagicSpellService spells,
|
||||
FileService.FileServiceClient files,
|
||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
||||
AccountUsernameService uname,
|
||||
AffiliationSpellService ars,
|
||||
EmailService mailer,
|
||||
@@ -229,28 +228,12 @@ public class AccountService(
|
||||
if (!string.IsNullOrEmpty(pictureId))
|
||||
{
|
||||
var file = await files.GetFileAsync(new GetFileRequest { Id = pictureId });
|
||||
await fileRefs.CreateReferenceAsync(
|
||||
new CreateReferenceRequest
|
||||
{
|
||||
ResourceId = account.Profile.ResourceIdentifier,
|
||||
FileId = pictureId,
|
||||
Usage = "profile.picture"
|
||||
}
|
||||
);
|
||||
account.Profile.Picture = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(backgroundId))
|
||||
{
|
||||
var file = await files.GetFileAsync(new GetFileRequest { Id = backgroundId });
|
||||
await fileRefs.CreateReferenceAsync(
|
||||
new CreateReferenceRequest
|
||||
{
|
||||
ResourceId = account.Profile.ResourceIdentifier,
|
||||
FileId = backgroundId,
|
||||
Usage = "profile.background"
|
||||
}
|
||||
);
|
||||
account.Profile.Background = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ public class BotAccountReceiverGrpc(
|
||||
AppDatabase db,
|
||||
AccountService accounts,
|
||||
FileService.FileServiceClient files,
|
||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
||||
AuthService authService
|
||||
)
|
||||
: BotAccountReceiverService.BotAccountReceiverServiceBase
|
||||
@@ -53,36 +52,12 @@ public class BotAccountReceiverGrpc(
|
||||
if (request.PictureId is not null)
|
||||
{
|
||||
var file = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId });
|
||||
if (account.Profile.Picture is not null)
|
||||
await fileRefs.DeleteResourceReferencesAsync(
|
||||
new DeleteResourceReferencesRequest { ResourceId = account.Profile.ResourceIdentifier }
|
||||
);
|
||||
await fileRefs.CreateReferenceAsync(
|
||||
new CreateReferenceRequest
|
||||
{
|
||||
ResourceId = account.Profile.ResourceIdentifier,
|
||||
FileId = request.PictureId,
|
||||
Usage = "profile.picture"
|
||||
}
|
||||
);
|
||||
account.Profile.Picture = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||
}
|
||||
|
||||
if (request.BackgroundId is not null)
|
||||
{
|
||||
var file = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId });
|
||||
if (account.Profile.Background is not null)
|
||||
await fileRefs.DeleteResourceReferencesAsync(
|
||||
new DeleteResourceReferencesRequest { ResourceId = account.Profile.ResourceIdentifier }
|
||||
);
|
||||
await fileRefs.CreateReferenceAsync(
|
||||
new CreateReferenceRequest
|
||||
{
|
||||
ResourceId = account.Profile.ResourceIdentifier,
|
||||
FileId = request.BackgroundId,
|
||||
Usage = "profile.background"
|
||||
}
|
||||
);
|
||||
account.Profile.Background = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ public class RealmController(
|
||||
AppDatabase db,
|
||||
RealmService rs,
|
||||
FileService.FileServiceClient files,
|
||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
||||
ActionLogService als,
|
||||
RelationshipService rels,
|
||||
AccountEventService accountEvents
|
||||
@@ -414,28 +413,6 @@ public class RealmController(
|
||||
Request
|
||||
);
|
||||
|
||||
var realmResourceId = $"realm:{realm.Id}";
|
||||
|
||||
if (realm.Picture is not null)
|
||||
{
|
||||
await fileRefs.CreateReferenceAsync(new CreateReferenceRequest
|
||||
{
|
||||
FileId = realm.Picture.Id,
|
||||
Usage = "realm.picture",
|
||||
ResourceId = realmResourceId
|
||||
});
|
||||
}
|
||||
|
||||
if (realm.Background is not null)
|
||||
{
|
||||
await fileRefs.CreateReferenceAsync(new CreateReferenceRequest
|
||||
{
|
||||
FileId = realm.Background.Id,
|
||||
Usage = "realm.background",
|
||||
ResourceId = realmResourceId
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(realm);
|
||||
}
|
||||
|
||||
@@ -478,24 +455,7 @@ public class RealmController(
|
||||
var pictureResult = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId });
|
||||
if (pictureResult is null) return BadRequest("Invalid picture id, unable to find the file on cloud.");
|
||||
|
||||
// Remove old references for the realm picture
|
||||
if (realm.Picture is not null)
|
||||
{
|
||||
await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest
|
||||
{
|
||||
ResourceId = realm.ResourceIdentifier
|
||||
});
|
||||
}
|
||||
|
||||
realm.Picture = SnCloudFileReferenceObject.FromProtoValue(pictureResult);
|
||||
|
||||
// Create a new reference
|
||||
await fileRefs.CreateReferenceAsync(new CreateReferenceRequest
|
||||
{
|
||||
FileId = realm.Picture.Id,
|
||||
Usage = "realm.picture",
|
||||
ResourceId = realm.ResourceIdentifier
|
||||
});
|
||||
}
|
||||
|
||||
if (request.BackgroundId is not null)
|
||||
@@ -503,24 +463,7 @@ public class RealmController(
|
||||
var backgroundResult = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId });
|
||||
if (backgroundResult is null) return BadRequest("Invalid background id, unable to find the file on cloud.");
|
||||
|
||||
// Remove old references for the realm background
|
||||
if (realm.Background is not null)
|
||||
{
|
||||
await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest
|
||||
{
|
||||
ResourceId = realm.ResourceIdentifier
|
||||
});
|
||||
}
|
||||
|
||||
realm.Background = SnCloudFileReferenceObject.FromProtoValue(backgroundResult);
|
||||
|
||||
// Create a new reference
|
||||
await fileRefs.CreateReferenceAsync(new CreateReferenceRequest
|
||||
{
|
||||
FileId = realm.Background.Id,
|
||||
Usage = "realm.background",
|
||||
ResourceId = realm.ResourceIdentifier
|
||||
});
|
||||
}
|
||||
|
||||
db.Realms.Update(realm);
|
||||
@@ -733,13 +676,6 @@ public class RealmController(
|
||||
Request
|
||||
);
|
||||
|
||||
// Delete all file references for this realm
|
||||
var realmResourceId = $"realm:{realm.Id}";
|
||||
await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest
|
||||
{
|
||||
ResourceId = realmResourceId
|
||||
});
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user