mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: update API routes for paste options and recent pastes
This commit is contained in:
@@ -115,6 +115,7 @@
|
|||||||
const token = getToken();
|
const token = getToken();
|
||||||
const refreshToken = getRefreshToken();
|
const refreshToken = getRefreshToken();
|
||||||
if (!token || !refreshToken) return null;
|
if (!token || !refreshToken) return null;
|
||||||
|
console.log('Refreshing tokens after TOTP change...');
|
||||||
const res = await fetch('/api/auth/refresh', {
|
const res = await fetch('/api/auth/refresh', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@@ -124,6 +125,7 @@
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.token?.token && data.token?.refreshToken && data.token?.success !== false) {
|
if (data.token?.token && data.token?.refreshToken && data.token?.success !== false) {
|
||||||
setTokens(data.token.token, data.token.refreshToken);
|
setTokens(data.token.token, data.token.refreshToken);
|
||||||
|
console.log('Tokens refreshed after TOTP change.');
|
||||||
return data.token.token as string;
|
return data.token.token as string;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ import type { LayoutServerLoad } from './$types';
|
|||||||
export const load: LayoutServerLoad = async ({ fetch, url }) => {
|
export const load: LayoutServerLoad = async ({ fetch, url }) => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/auth/info');
|
const res = await fetch('/api/auth/info');
|
||||||
|
const pasteOptionsRes = await fetch('/api/paste/info');
|
||||||
const options = await res.json();
|
const options = await res.json();
|
||||||
return { options, url: url.href };
|
const pasteOptions = await pasteOptionsRes.json();
|
||||||
|
return { options, pasteOptions, url: url.href };
|
||||||
} catch {
|
} catch {
|
||||||
return { options: null, url: url.href };
|
return { options: null, pasteOptions: null, url: url.href };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { PageServerLoad } from './$types';
|
|||||||
|
|
||||||
export const load: PageServerLoad = async ({ fetch, url }) => {
|
export const load: PageServerLoad = async ({ fetch, url }) => {
|
||||||
try {
|
try {
|
||||||
const optionsRes = await fetch('/api/paste/create/options');
|
const optionsRes = await fetch('/api/paste/info');
|
||||||
const authInfo = await fetch('/api/auth/info');
|
const authInfo = await fetch('/api/auth/info');
|
||||||
const options = await optionsRes.json();
|
const options = await optionsRes.json();
|
||||||
const auth = await authInfo.json();
|
const auth = await authInfo.json();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export const load: PageServerLoad = async ({ params, fetch, url }) => {
|
|||||||
}
|
}
|
||||||
const pasteData = (await paste.json()) as Paste;
|
const pasteData = (await paste.json()) as Paste;
|
||||||
const pasteContent = await fetch(`/api/paste/${id}/raw`);
|
const pasteContent = await fetch(`/api/paste/${id}/raw`);
|
||||||
const pasteOptions = await fetch('/api/paste/create/options');
|
const pasteOptions = await fetch('/api/paste/info');
|
||||||
const options = await pasteOptions.json();
|
const options = await pasteOptions.json();
|
||||||
const content = await pasteContent.text();
|
const content = await pasteContent.text();
|
||||||
|
|
||||||
|
|||||||
@@ -206,7 +206,28 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("create/options")]
|
[Route("recent")]
|
||||||
|
public async Task<IActionResult> GetRecentPastes()
|
||||||
|
{
|
||||||
|
var results = await _pasteService.GetList(0, 50, true);
|
||||||
|
return Ok(results.Select(p => new
|
||||||
|
{
|
||||||
|
p.ID,
|
||||||
|
p.UUID,
|
||||||
|
p.Title,
|
||||||
|
p.Size,
|
||||||
|
p.TrueSize,
|
||||||
|
p.IsCompressed,
|
||||||
|
p.Views,
|
||||||
|
p.Syntax,
|
||||||
|
p.Visibility,
|
||||||
|
p.ExpiresAt,
|
||||||
|
p.EditedAt
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("info")]
|
||||||
public IActionResult GetCreatePasteOptions()
|
public IActionResult GetCreatePasteOptions()
|
||||||
{
|
{
|
||||||
var options = new
|
var options = new
|
||||||
|
|||||||
@@ -66,12 +66,15 @@ namespace SharpbinV3.Server.Services
|
|||||||
}
|
}
|
||||||
public async Task<bool> EditText(Paste paste, string text)
|
public async Task<bool> EditText(Paste paste, string text)
|
||||||
{
|
{
|
||||||
var compressedData = _cs.Compress(text);
|
var data = Encoding.UTF8.GetBytes(text);
|
||||||
paste.Content = compressedData;
|
if (_pasteSettings.EnablePasteCompression)
|
||||||
paste.Size = compressedData.Length;
|
data = _cs.Compress(text);
|
||||||
|
|
||||||
|
paste.Content = data;
|
||||||
|
paste.Size = data.Length;
|
||||||
paste.TrueSize = Encoding.UTF8.GetByteCount(text);
|
paste.TrueSize = Encoding.UTF8.GetByteCount(text);
|
||||||
paste.EditedAt = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
paste.EditedAt = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||||
paste.IsCompressed = compressedData.Length < Encoding.UTF8.GetByteCount(text);
|
paste.IsCompressed = data.Length < Encoding.UTF8.GetByteCount(text);
|
||||||
_db.Pastes.Update(paste);
|
_db.Pastes.Update(paste);
|
||||||
var result = await _db.SaveChangesAsync();
|
var result = await _db.SaveChangesAsync();
|
||||||
return result > 0;
|
return result > 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user