added media class
This commit is contained in:
@@ -20,6 +20,7 @@ public class Media
|
|||||||
public string[] Tags { get; set; } = [];
|
public string[] Tags { get; set; } = [];
|
||||||
public Size? Dimensions { get; set; }
|
public Size? Dimensions { get; set; }
|
||||||
public Dictionary<ThumbnailSize, ObjectId> Thumbnails { get; set; } = [];
|
public Dictionary<ThumbnailSize, ObjectId> Thumbnails { get; set; } = [];
|
||||||
|
public MediaClass Class { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public static readonly Dictionary<string, MediaType> KnownTypes = new()
|
public static readonly Dictionary<string, MediaType> KnownTypes = new()
|
||||||
@@ -117,3 +118,10 @@ public enum MediaType
|
|||||||
Code,
|
Code,
|
||||||
Raw
|
Raw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum MediaClass
|
||||||
|
{
|
||||||
|
Standard,
|
||||||
|
NSFW,
|
||||||
|
Secret
|
||||||
|
}
|
||||||
@@ -25,25 +25,28 @@ public class AobaService(IMongoDatabase db)
|
|||||||
return await _media.Find(m => m.MediaId == id).FirstOrDefaultAsync(cancellationToken);
|
return await _media.Find(m => m.MediaId == id).FirstOrDefaultAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PagedResult<Media>> FindMediaAsync(string? query, ObjectId userId, int page = 1, int pageSize = 100)
|
public async Task<PagedResult<Media>> FindMediaAsync(string? query, ObjectId userId, int page = 1, int pageSize = 100, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var filter = Builders<Media>.Filter.And([
|
var filters = new List<FilterDefinition<Media>>()
|
||||||
|
{
|
||||||
string.IsNullOrWhiteSpace(query) ? "{}" : Builders<Media>.Filter.Text(query),
|
string.IsNullOrWhiteSpace(query) ? "{}" : Builders<Media>.Filter.Text(query),
|
||||||
Builders<Media>.Filter.Eq(m => m.Owner, userId)
|
Builders<Media>.Filter.Eq(m => m.Owner, userId)
|
||||||
]);
|
};
|
||||||
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
|
filters.Add(Builders<Media>.Filter.Ne(m => m.Class, MediaClass.Secret));
|
||||||
var sort = Builders<Media>.Sort.Descending(m => m.UploadDate);
|
var sort = Builders<Media>.Sort.Descending(m => m.UploadDate);
|
||||||
var find = _media.Find(filter);
|
var find = _media.Find(Builders<Media>.Filter.And(filters));
|
||||||
|
|
||||||
var total = await find.CountDocumentsAsync();
|
var total = await find.CountDocumentsAsync(cancellationToken);
|
||||||
page -= 1;
|
page -= 1;
|
||||||
var items = await find.Sort(sort).Skip(page * pageSize).Limit(pageSize).ToListAsync();
|
var items = await find.Sort(sort).Skip(page * pageSize).Limit(pageSize).ToListAsync(cancellationToken);
|
||||||
return new PagedResult<Media>(items, page, pageSize, (int)total);
|
return new PagedResult<Media>(items, page, pageSize, (int)total);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<Media>> FindMediaWithExtAsync(string ext, CancellationToken cancellationToken = default)
|
public async Task<List<Media>> FindMediaWithExtAsync(string ext, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var filter = Builders<Media>.Filter.Eq(m => m.Ext, ext);
|
var filter = Builders<Media>.Filter.Eq(m => m.Ext, ext);
|
||||||
return await _media.Find(filter).ToListAsync();
|
return await _media.Find(filter).ToListAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task AddMediaAsync(Media media, CancellationToken cancellationToken = default)
|
public Task AddMediaAsync(Media media, CancellationToken cancellationToken = default)
|
||||||
@@ -51,6 +54,13 @@ public class AobaService(IMongoDatabase db)
|
|||||||
return _media.InsertOneAsync(media, null, cancellationToken);
|
return _media.InsertOneAsync(media, null, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task SetMediaClassAsync(ObjectId mediaId, MediaClass mediaClass, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var update = Builders<Media>.Update
|
||||||
|
.Set(m => m.Class, mediaClass);
|
||||||
|
await _media.UpdateOneAsync(m => m.MediaId == mediaId, update, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task AddThumbnailAsync(ObjectId mediaId, ObjectId thumbId, ThumbnailSize size, CancellationToken cancellationToken = default)
|
public async Task AddThumbnailAsync(ObjectId mediaId, ObjectId thumbId, ThumbnailSize size, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var upate = Builders<Media>.Update.Set(m => m.Thumbnails[size], thumbId);
|
var upate = Builders<Media>.Update.Set(m => m.Thumbnails[size], thumbId);
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ service AobaRpc {
|
|||||||
rpc ListMedia(PageFilter) returns (ListResponse);
|
rpc ListMedia(PageFilter) returns (ListResponse);
|
||||||
rpc GetUser(Id) returns (UserResponse);
|
rpc GetUser(Id) returns (UserResponse);
|
||||||
rpc GetShareXDestination(google.protobuf.Empty) returns (ShareXResponse);
|
rpc GetShareXDestination(google.protobuf.Empty) returns (ShareXResponse);
|
||||||
|
rpc SetMediaClass(SetMediaClassRequest) returns(google.protobuf.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ message Credentials{
|
|||||||
string password = 2;
|
string password = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message SetMediaClassRequest{
|
||||||
|
Id id = 1;
|
||||||
|
MediaClass class = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
message Jwt{
|
message Jwt{
|
||||||
@@ -81,6 +84,7 @@ message MediaModel {
|
|||||||
Id owner = 6;
|
Id owner = 6;
|
||||||
string thumbUrl = 7;
|
string thumbUrl = 7;
|
||||||
string mediaUrl = 8;
|
string mediaUrl = 8;
|
||||||
|
MediaClass class = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MediaType {
|
enum MediaType {
|
||||||
@@ -92,6 +96,12 @@ enum MediaType {
|
|||||||
Raw = 5;
|
Raw = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum MediaClass {
|
||||||
|
Standard = 0;
|
||||||
|
NSFW = 1;
|
||||||
|
Secret = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message ShareXResponse {
|
message ShareXResponse {
|
||||||
oneof dstResult {
|
oneof dstResult {
|
||||||
string destination = 1;
|
string destination = 1;
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ using Google.Protobuf.WellKnownTypes;
|
|||||||
|
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
|
|
||||||
using MongoDB.Bson.IO;
|
|
||||||
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace AobaServer.Services;
|
namespace AobaServer.Services;
|
||||||
|
|
||||||
@@ -20,7 +17,7 @@ public class AobaRpcService(AobaService aobaService, AccountsService accountsSer
|
|||||||
{
|
{
|
||||||
public override async Task<MediaResponse> GetMedia(Id request, ServerCallContext context)
|
public override async Task<MediaResponse> GetMedia(Id request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
var media = await aobaService.GetMediaFromLegacyIdAsync(request.ToObjectId());
|
var media = await aobaService.GetMediaFromLegacyIdAsync(request.ToObjectId(), context.CancellationToken);
|
||||||
return media.ToResponse();
|
return media.ToResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +28,12 @@ public class AobaRpcService(AobaService aobaService, AccountsService accountsSer
|
|||||||
return result.ToResponse();
|
return result.ToResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<Empty> SetMediaClass(SetMediaClassRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
await aobaService.SetMediaClassAsync(request.Id.ToObjectId(), (AobaCore.Models.MediaClass)request.Class, context.CancellationToken);
|
||||||
|
return new Empty();
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task<ShareXResponse> GetShareXDestination(Empty request, ServerCallContext context)
|
public override async Task<ShareXResponse> GetShareXDestination(Empty request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
var userId = context.GetHttpContext().User.GetId();
|
var userId = context.GetHttpContext().User.GetId();
|
||||||
@@ -50,10 +53,7 @@ public class AobaRpcService(AobaService aobaService, AccountsService accountsSer
|
|||||||
};
|
};
|
||||||
return new ShareXResponse
|
return new ShareXResponse
|
||||||
{
|
{
|
||||||
Destination = JsonSerializer.Serialize(dest, new JsonSerializerOptions
|
Destination = JsonSerializer.Serialize(dest)
|
||||||
{
|
|
||||||
WriteIndented = true
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ public static class ProtoExtensions
|
|||||||
Owner = media.Owner.ToId(),
|
Owner = media.Owner.ToId(),
|
||||||
ViewCount = media.ViewCount,
|
ViewCount = media.ViewCount,
|
||||||
ThumbUrl = thumbUrl,
|
ThumbUrl = thumbUrl,
|
||||||
MediaUrl = media.GetMediaUrl()
|
MediaUrl = media.GetMediaUrl(),
|
||||||
|
Class = (Aoba.RPC.MediaClass)media.Class,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user