mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: seo optimizations + opengraph embeds
fix: nullable AuthorUUIDs; assign admins member & mod role
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ fetch }) => {
|
export const load: PageServerLoad = async ({ fetch,url }) => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/paste/create/options');
|
const res = await fetch('/api/paste/create/options');
|
||||||
const options = await res.json();
|
const options = await res.json();
|
||||||
return { options };
|
return { options, url: url.href };
|
||||||
} catch {
|
} catch {
|
||||||
return { options: null };
|
return { options: null, url: url.href };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -90,6 +90,15 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Create a Paste - Sharpbin</title>
|
||||||
|
<meta property="og:title" content="Create a Paste - Sharpbin" />
|
||||||
|
<meta property="og:description" content="Create and share your pastes easily with Sharpbin." />
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:url" content="{data.url}" />
|
||||||
|
<meta property="og:site_name" content="Sharpbin" />
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<main
|
<main
|
||||||
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import type { Paste } from '$lib/types/paste';
|
import type { Paste } from '$lib/types/paste';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, fetch }) => {
|
export const load: PageServerLoad = async ({ params, fetch, url }) => {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
|
|
||||||
const paste = await fetch(`/api/paste/${id}`);
|
const paste = await fetch(`/api/paste/${id}`);
|
||||||
@@ -17,5 +17,5 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
|
|||||||
const options = await pasteOptions.json();
|
const options = await pasteOptions.json();
|
||||||
const content = await pasteContent.text();
|
const content = await pasteContent.text();
|
||||||
|
|
||||||
return { paste: pasteData, content, options };
|
return { paste: pasteData, content, options, url: url.href };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -282,6 +282,31 @@
|
|||||||
$: if (data?.paste && (data.paste.visibility !== 2 || decryptedContent !== null)) renderCode();
|
$: if (data?.paste && (data.paste.visibility !== 2 || decryptedContent !== null)) renderCode();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>{data.paste ? (data.paste.title || 'Untitled Paste') + ' - Sharpbin' : 'Paste Not Found - Sharpbin'}</title>
|
||||||
|
{#if data.paste}
|
||||||
|
<meta property="og:title" content={data.paste.title || 'Untitled Paste'} />
|
||||||
|
<meta
|
||||||
|
property="og:description"
|
||||||
|
content={`A paste on Sharpbin created by ${
|
||||||
|
data.paste.author ? data.paste.author.username : 'Anonymous'
|
||||||
|
}, created on ${
|
||||||
|
extractDateFromUUIDv7(data.paste.uuid)?.toLocaleDateString() ?? 'Unknown Date'
|
||||||
|
}.`}
|
||||||
|
/>
|
||||||
|
<meta property="og:type" content="article" />
|
||||||
|
<meta property="og:url" content={data.url} />
|
||||||
|
<meta property="og:site_name" content="Sharpbin" />
|
||||||
|
<meta property="og:article:published_time" content={extractDateFromUUIDv7(data.paste.uuid)?.toISOString() ?? ''} />
|
||||||
|
{#if data.paste.editedAt}
|
||||||
|
<meta property="og:article:modified_time" content={new Date(data.paste.editedAt).toISOString()} />
|
||||||
|
{/if}
|
||||||
|
{#if data.paste.author}
|
||||||
|
<meta property="og:article:author" content={data.paste.author.username} />
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<main
|
<main
|
||||||
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { PageServerLoad } from './$types';
|
|||||||
import { getServerToken } from '$lib/utils/auth';
|
import { getServerToken } from '$lib/utils/auth';
|
||||||
import type { User } from '$lib/types/user';
|
import type { User } from '$lib/types/user';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, fetch, cookies }) => {
|
export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
|
||||||
const { username } = params;
|
const { username } = params;
|
||||||
const token = getServerToken(cookies);
|
const token = getServerToken(cookies);
|
||||||
const res = await fetch(`/api/user/${username}`, {
|
const res = await fetch(`/api/user/${username}`, {
|
||||||
@@ -12,5 +12,5 @@ export const load: PageServerLoad = async ({ params, fetch, cookies }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const user = (await res.json()) as User;
|
const user = (await res.json()) as User;
|
||||||
return { user };
|
return { user, url: url.href };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -113,6 +113,17 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>{data.user.displayName || data.user.username} - User Profile</title>
|
||||||
|
|
||||||
|
<meta property="og:title" content="{data.user.displayName || data.user.username} - User Profile" />
|
||||||
|
<meta property="og:description" content="View the profile and {pagination.totalCount} paste{pagination.totalCount !== 1 ? 's' : ''} of {data.user.displayName || data.user.username} on Sharpbin." />
|
||||||
|
<meta property="og:type" content="profile" />
|
||||||
|
<meta property="og:url" content="{data.url}" />
|
||||||
|
<meta property="og:site_name" content="Sharpbin" />
|
||||||
|
<meta property="profile:username" content="{data.user.username}" />
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<main
|
<main
|
||||||
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ const allowedHosts = process.env.VITE_ALLOWED_HOSTS
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [tailwindcss(), sveltekit()],
|
plugins: [tailwindcss(), sveltekit()],
|
||||||
server: {
|
server: {
|
||||||
|
host: true,
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': apiUrl
|
'/api': apiUrl
|
||||||
}
|
},
|
||||||
|
allowedHosts: allowedHosts
|
||||||
},
|
},
|
||||||
preview: {
|
preview: {
|
||||||
allowedHosts: allowedHosts
|
allowedHosts: allowedHosts
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace SharpbinV3.Server.Data.Entities
|
|||||||
public required string ID { get; set; }
|
public required string ID { get; set; }
|
||||||
public string? Title { get; set; }
|
public string? Title { get; set; }
|
||||||
|
|
||||||
public required Guid AuthorUUID { get; set; } = Guid.Empty; // uuid of the user who created the paste, or Guid.Empty for anonymous pastes
|
public Guid? AuthorUUID { get; set; } // uuid of the user who created the paste, or null for anonymous pastes
|
||||||
public User? User { get; set; }
|
public User? User { get; set; }
|
||||||
|
|
||||||
public long? EditedAt { get; set; }
|
public long? EditedAt { get; set; }
|
||||||
|
|||||||
@@ -0,0 +1,191 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using SharpbinV3.Server.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SharpbinV3.Server.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(AppDbContext))]
|
||||||
|
[Migration("20260106211303_NullableAuthorUUID")]
|
||||||
|
partial class NullableAuthorUUID
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "10.0.0");
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("PID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid?>("AuthorUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<byte[]>("Content")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("BLOB");
|
||||||
|
|
||||||
|
b.Property<long?>("EditedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("ExpiresAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("ID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("IsCompressed")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("Size")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Syntax")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long>("TrueSize")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid>("UUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Views")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Visibility")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("PID");
|
||||||
|
|
||||||
|
b.HasIndex("AuthorUUID");
|
||||||
|
|
||||||
|
b.HasIndex("ExpiresAt");
|
||||||
|
|
||||||
|
b.HasIndex("ID")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("PID")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("UUID")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("Views");
|
||||||
|
|
||||||
|
b.HasIndex("Visibility");
|
||||||
|
|
||||||
|
b.ToTable("Pastes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.RefreshToken", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("UserUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long>("CreatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("ExpiresAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("JwtId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Token")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("Used")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("UserUUID");
|
||||||
|
|
||||||
|
b.ToTable("RefreshTokens");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("UUID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("DisplayName")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long?>("LastLogin")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordHash")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string>("Roles")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int?>("UID")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Visibility")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("UUID");
|
||||||
|
|
||||||
|
b.HasIndex("UID");
|
||||||
|
|
||||||
|
b.HasIndex("UUID")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
||||||
|
.WithMany("Pastes")
|
||||||
|
.HasForeignKey("AuthorUUID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.RefreshToken", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
||||||
|
.WithMany("RefreshTokens")
|
||||||
|
.HasForeignKey("UserUUID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Pastes");
|
||||||
|
|
||||||
|
b.Navigation("RefreshTokens");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SharpbinV3.Server.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class NullableAuthorUUID : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<Guid>(
|
||||||
|
name: "AuthorUUID",
|
||||||
|
table: "Pastes",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(Guid),
|
||||||
|
oldType: "TEXT");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<Guid>(
|
||||||
|
name: "AuthorUUID",
|
||||||
|
table: "Pastes",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
|
||||||
|
oldClrType: typeof(Guid),
|
||||||
|
oldType: "TEXT",
|
||||||
|
oldNullable: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ namespace SharpbinV3.Server.Migrations
|
|||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<Guid>("AuthorUUID")
|
b.Property<Guid?>("AuthorUUID")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<byte[]>("Content")
|
b.Property<byte[]>("Content")
|
||||||
@@ -160,8 +160,7 @@ namespace SharpbinV3.Server.Migrations
|
|||||||
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
||||||
.WithMany("Pastes")
|
.WithMany("Pastes")
|
||||||
.HasForeignKey("AuthorUUID")
|
.HasForeignKey("AuthorUUID")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace SharpbinV3.Server.Services
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (_authSettings.First_User_Admin && !await _db.Users.AnyAsync())
|
if (_authSettings.First_User_Admin && !await _db.Users.AnyAsync())
|
||||||
user.Roles = [255];
|
user.Roles = [0,1,255];
|
||||||
|
|
||||||
_db.Users.Add(user);
|
_db.Users.Add(user);
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace SharpbinV3.Server.Services
|
|||||||
UUID = Guid.CreateVersion7(),
|
UUID = Guid.CreateVersion7(),
|
||||||
ID = Utilities.GenerateRandomString(8),
|
ID = Utilities.GenerateRandomString(8),
|
||||||
Title = title,
|
Title = title,
|
||||||
AuthorUUID = author?.UUID ?? Guid.Empty,
|
AuthorUUID = author?.UUID,
|
||||||
User = author,
|
User = author,
|
||||||
Content = compressedData,
|
Content = compressedData,
|
||||||
Size = compressedData.Length,
|
Size = compressedData.Length,
|
||||||
|
|||||||
Reference in New Issue
Block a user