[backend] Add sensitive field to emojis
This commit is contained in:
parent
c1e348b0d5
commit
b3b2adb127
8 changed files with 67 additions and 15 deletions
|
@ -37,7 +37,8 @@ public class EmojiController(
|
|||
Aliases = p.Aliases,
|
||||
Category = p.Category,
|
||||
PublicUrl = p.PublicUrl,
|
||||
License = p.License
|
||||
License = p.License,
|
||||
Sensitive = p.Sensitive
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
@ -58,7 +59,8 @@ public class EmojiController(
|
|||
Aliases = emoji.Aliases,
|
||||
Category = emoji.Category,
|
||||
PublicUrl = emoji.PublicUrl,
|
||||
License = emoji.License
|
||||
License = emoji.License,
|
||||
Sensitive = emoji.Sensitive
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -78,7 +80,8 @@ public class EmojiController(
|
|||
Aliases = [],
|
||||
Category = null,
|
||||
PublicUrl = emoji.PublicUrl,
|
||||
License = null
|
||||
License = null,
|
||||
Sensitive = false
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -103,7 +106,8 @@ public class EmojiController(
|
|||
Aliases = [],
|
||||
Category = null,
|
||||
PublicUrl = cloned.PublicUrl,
|
||||
License = null
|
||||
License = null,
|
||||
Sensitive = cloned.Sensitive
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -125,7 +129,7 @@ public class EmojiController(
|
|||
public async Task<EmojiResponse> UpdateEmoji(string id, UpdateEmojiRequest request)
|
||||
{
|
||||
var emoji = await emojiSvc.UpdateLocalEmoji(id, request.Name, request.Aliases, request.Category,
|
||||
request.License) ??
|
||||
request.License, request.Sensitive) ??
|
||||
throw GracefulException.NotFound("Emoji not found");
|
||||
|
||||
return new EmojiResponse
|
||||
|
@ -136,7 +140,8 @@ public class EmojiController(
|
|||
Aliases = emoji.Aliases,
|
||||
Category = emoji.Category,
|
||||
PublicUrl = emoji.PublicUrl,
|
||||
License = emoji.License
|
||||
License = emoji.License,
|
||||
Sensitive = emoji.Sensitive
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -191,7 +191,8 @@ public class NoteRenderer(
|
|||
Aliases = p.Aliases,
|
||||
Category = p.Category,
|
||||
PublicUrl = p.PublicUrl,
|
||||
License = p.License
|
||||
License = p.License,
|
||||
Sensitive = p.Sensitive
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
|
|
@ -1024,6 +1024,10 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
|||
.HasColumnName("publicUrl")
|
||||
.HasDefaultValueSql("''::character varying");
|
||||
|
||||
b.Property<bool>("Sensitive")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("sensitive");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Iceshrimp.Backend.Core.Database.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20240919080240_SensitiveEmoji")]
|
||||
public partial class SensitiveEmoji : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "sensitive",
|
||||
table: "emoji",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "sensitive",
|
||||
table: "emoji");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,6 +57,9 @@ public class Emoji
|
|||
[Column("height")]
|
||||
public int? Height { get; set; }
|
||||
|
||||
[Column("sensitive")]
|
||||
public bool Sensitive { get; set; }
|
||||
|
||||
public string GetPublicUri(Config.InstanceSection config) => Host == null
|
||||
? $"https://{config.WebDomain}/emoji/{Name}"
|
||||
: throw new Exception("Cannot access PublicUri for remote emoji");
|
||||
|
|
|
@ -56,7 +56,8 @@ public partial class EmojiService(
|
|||
OriginalUrl = driveFile.Url,
|
||||
PublicUrl = driveFile.AccessUrl,
|
||||
Width = driveFile.Properties.Width,
|
||||
Height = driveFile.Properties.Height
|
||||
Height = driveFile.Properties.Height,
|
||||
Sensitive = false
|
||||
};
|
||||
emoji.Uri = emoji.GetPublicUri(config.Value);
|
||||
|
||||
|
@ -81,7 +82,8 @@ public partial class EmojiService(
|
|||
OriginalUrl = driveFile.Url,
|
||||
PublicUrl = driveFile.AccessUrl,
|
||||
Width = driveFile.Properties.Width,
|
||||
Height = driveFile.Properties.Height
|
||||
Height = driveFile.Properties.Height,
|
||||
Sensitive = existing.Sensitive
|
||||
};
|
||||
emoji.Uri = emoji.GetPublicUri(config.Value);
|
||||
|
||||
|
@ -130,7 +132,8 @@ public partial class EmojiService(
|
|||
UpdatedAt = DateTime.UtcNow,
|
||||
OriginalUrl = emojo.Image?.Url?.Link ?? throw new Exception("Emoji.Image has no url"),
|
||||
PublicUrl = emojo.Image.Url.Link,
|
||||
Uri = emojo.Id
|
||||
Uri = emojo.Id,
|
||||
Sensitive = false
|
||||
};
|
||||
await db.AddAsync(dbEmojo);
|
||||
await db.SaveChangesAsync();
|
||||
|
@ -204,7 +207,7 @@ public partial class EmojiService(
|
|||
}
|
||||
|
||||
public async Task<Emoji?> UpdateLocalEmoji(
|
||||
string id, string? name, List<string>? aliases, string? category, string? license
|
||||
string id, string? name, List<string>? aliases, string? category, string? license, bool? sensitive
|
||||
)
|
||||
{
|
||||
var emoji = await db.Emojis.FirstOrDefaultAsync(p => p.Id == id);
|
||||
|
@ -228,6 +231,8 @@ public partial class EmojiService(
|
|||
|
||||
if (license != null) emoji.License = license;
|
||||
|
||||
if (sensitive.HasValue) emoji.Sensitive = sensitive.Value;
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return emoji;
|
||||
|
|
|
@ -9,4 +9,5 @@ public class EmojiResponse
|
|||
public required string? Category { get; set; }
|
||||
public required string PublicUrl { get; set; }
|
||||
public required string? License { get; set; }
|
||||
public required bool Sensitive { get; set; }
|
||||
}
|
|
@ -6,4 +6,5 @@ public class UpdateEmojiRequest
|
|||
public List<string>? Aliases { get; set; }
|
||||
public string? Category { get; set; }
|
||||
public string? License { get; set; }
|
||||
public bool? Sensitive { get; set; }
|
||||
}
|
Loading…
Add table
Reference in a new issue