mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-25 11:31:46 +00:00
refactor: auto format
This commit is contained in:
parent
04f905a841
commit
100d37e552
@ -18,10 +18,10 @@ export function hexToRgb(hex: string): Color | null {
|
||||
const result = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
return result
|
||||
? {
|
||||
r: parseInt(result[1], 16),
|
||||
g: parseInt(result[2], 16),
|
||||
b: parseInt(result[3], 16)
|
||||
}
|
||||
r: parseInt(result[1], 16),
|
||||
g: parseInt(result[2], 16),
|
||||
b: parseInt(result[3], 16)
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -36,7 +36,5 @@ export function getLuminance(rgb: Color): number {
|
||||
|
||||
// Convert an rgb color object to a hex color string
|
||||
export function rgbToHex(color: Color): string {
|
||||
return [color.r, color.g, color.b]
|
||||
.map((e) => e.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
return [color.r, color.g, color.b].map((e) => e.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
@ -5,10 +5,9 @@ export async function redirectAPI({ form, fdata }: { form?: HTMLFormElement; fda
|
||||
else if (!fdata) throw new Error('No formdata provided!');
|
||||
|
||||
// Get endpoint, prefer form, then formdata or empty
|
||||
const endpoint = (form?.dataset.endpoint ?? fdata.get('endpoint')) ?? '';
|
||||
const endpoint = form?.dataset.endpoint ?? fdata.get('endpoint') ?? '';
|
||||
// Append endpoint to formdata
|
||||
if (!fdata?.has('endpoint'))
|
||||
fdata.append('endpoint', endpoint);
|
||||
if (!fdata?.has('endpoint')) fdata.append('endpoint', endpoint);
|
||||
|
||||
// Send request to be redirected to given endpoint
|
||||
const response = await fetch('/api/redirect', {
|
||||
|
@ -46,9 +46,6 @@ export function createGridArray(matrix: Matrix): MatrixCell[][] {
|
||||
const { factor } = scale;
|
||||
|
||||
return Array.from({ length: height / factor }, (_, y) =>
|
||||
Array.from(
|
||||
{ length: width / factor },
|
||||
(_, x) => ({ x, y, color: '000000' }) as MatrixCell
|
||||
)
|
||||
Array.from({ length: width / factor }, (_, x) => ({ x, y, color: '000000' }) as MatrixCell)
|
||||
) as MatrixCell[][];
|
||||
}
|
||||
|
@ -227,7 +227,9 @@
|
||||
matrix = initializeMatrix();
|
||||
matrix.scale = {
|
||||
factor: 4,
|
||||
// 0.1875 (made up padding) * 192 (height when it was made up) * 4 (scaling when it was made up)
|
||||
// 0.1875 (made up padding) *
|
||||
// 192 (height when it was made up) *
|
||||
// 4 (scaling when it was made up)
|
||||
padding: 144 / matrix.width
|
||||
};
|
||||
matrix.grid = createGridArray(matrix);
|
||||
|
@ -1,28 +1,28 @@
|
||||
import type { APIResponse } from "$lib/interfaces";
|
||||
import { json, type RequestHandler } from "@sveltejs/kit";
|
||||
import type { APIResponse } from '$lib/interfaces';
|
||||
import { json, type RequestHandler } from '@sveltejs/kit';
|
||||
|
||||
export const GET: RequestHandler = async ({ url }) => {
|
||||
// Get endpoint on main API from searchparams
|
||||
const params = url.searchParams;
|
||||
const subreddit = params.get('subreddit');
|
||||
// Return if param not found
|
||||
if (subreddit === null) return json({ success: false } as APIResponse);
|
||||
// Get endpoint on main API from searchparams
|
||||
const params = url.searchParams;
|
||||
const subreddit = params.get('subreddit');
|
||||
// Return if param not found
|
||||
if (subreddit === null) return json({ success: false } as APIResponse);
|
||||
|
||||
// Get subreddit page data
|
||||
const response = await fetch(`https://www.reddit.com/r/${subreddit}/`, {
|
||||
headers: new Headers({
|
||||
"User-Agent": "MatrixRedditMemes/0.0.1"
|
||||
})
|
||||
});
|
||||
// Read data as string
|
||||
const text = await response.text();
|
||||
// Get subreddit page data
|
||||
const response = await fetch(`https://www.reddit.com/r/${subreddit}/`, {
|
||||
headers: new Headers({
|
||||
'User-Agent': 'MatrixRedditMemes/0.0.1'
|
||||
})
|
||||
});
|
||||
// Read data as string
|
||||
const text = await response.text();
|
||||
|
||||
// Get all sources of posts
|
||||
const regex = /<img[^>]+role="presentation"[^>]+src="(.*?)"[^>]*>/g;
|
||||
let results = [], match;
|
||||
while ((match = regex.exec(text)) !== null)
|
||||
results.push(match[1]);
|
||||
// Get all sources of posts
|
||||
const regex = /<img[^>]+role="presentation"[^>]+src="(.*?)"[^>]*>/g;
|
||||
let results = [],
|
||||
match;
|
||||
while ((match = regex.exec(text)) !== null) results.push(match[1]);
|
||||
|
||||
// Return source data
|
||||
return json({ success: true, results } as APIResponse);
|
||||
// Return source data
|
||||
return json({ success: true, results } as APIResponse);
|
||||
};
|
||||
|
@ -10,11 +10,13 @@
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler",
|
||||
"plugins": [{
|
||||
"name": "typescript-svelte-plugin",
|
||||
"assumeIsSvelteProject": false,
|
||||
"enabled": true
|
||||
}]
|
||||
"plugins": [
|
||||
{
|
||||
"name": "typescript-svelte-plugin",
|
||||
"assumeIsSvelteProject": false,
|
||||
"enabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
||||
//
|
||||
|
@ -6,5 +6,5 @@ export default defineConfig({
|
||||
test: {
|
||||
include: ['src/**/*.{test,spec}.{js,ts}'],
|
||||
exclude: ['src/playwright']
|
||||
},
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user