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
@ -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,5 +1,5 @@
|
|||||||
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
|
||||||
@ -11,7 +11,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||||||
// 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
|
||||||
@ -19,9 +19,9 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||||||
|
|
||||||
// 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",
|
"name": "typescript-svelte-plugin",
|
||||||
"assumeIsSvelteProject": false,
|
"assumeIsSvelteProject": false,
|
||||||
"enabled": true
|
"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