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