Skip to content

Commit

Permalink
fix: dump changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Coobaha committed Oct 29, 2023
1 parent 4512166 commit 754da92
Show file tree
Hide file tree
Showing 29 changed files with 3,315 additions and 1,859 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ profile-*
dist
scripts/

ecosystem.config.cjs
ecosystem.config.js
8 changes: 7 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
"printWidth": 80,
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": ["./web", "."],
"svelteSortOrder": "scripts-markup-styles",
"svelteSortOrder": "options-styles-scripts-markup",
"svelteStrictMode": true,
"svelteBracketNewLine": true,
"svelteAllowShorthand": true,
"svelteIndentScriptAndStyle": true,
"overrides": [
{
"files": "*.svelte",
"options": {
"parser": "svelte"
}
},
{
"files": ["*.js", "*.jsx", "*.ts", "*.tsx", "*.svelte"],
"options": {
Expand Down
18 changes: 9 additions & 9 deletions alfred/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
"email": "[email protected]"
},
"dependencies": {
"@jxa/global-type": "^1.3.5",
"@jxa/run": "^1.3.5",
"@jxa/global-type": "1.3.5",
"@jxa/run": "1.3.5",
"alfy": "0.11.1",
"convert-layout": "^0.11.1",
"convert-layout": "0.11.1",
"default-browser": "2.0.1",
"minisearch": "4.0.3",
"patch-package": "^6.4.7",
"ts-node": "^10.9.1"
"patch-package": "6.4.7",
"ts-node": "10.9.1"
},
"devDependencies": {
"@types/chrome": "^0.0.193",
"@types/convert-layout": "^0.5.1",
"ts-node-dev": "^2.0.0",
"typescript": "^4.9.4"
"@types/chrome": "0.0.248",
"@types/convert-layout": "0.5.2",
"ts-node-dev": "2.0.0",
"typescript": "5.2.2"
},
"engines": {
"node": ">=14.16"
Expand Down
1 change: 1 addition & 0 deletions anki/plugin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def anki_connect_setup(parent=None) -> None:
if settings.ankiconnect is None:
return


if settings.ankiconnect is False:
add_new_handlers()
return
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
"name": "suomea",
"version": "1.0.0",
"dependencies": {
"husky": "^8.0.1",
"husky": "8.0.1",
"lage": "1.7.2",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"syncpack": "^8.2.4",
"typescript": "^4.9.4",
"typesync": "^0.9.2"
"lint-staged": "13.0.3",
"prettier": "3.0.3",
"syncpack": "11.2.1",
"typescript": "5.2.2",
"typesync": "0.11.1"
},
"devDependencies": {
"@tsconfig/node18-strictest": "^1.0.0",
"@types/prettier": "^2.7.0",
"@tsconfig/node20": "20.1.2",
"@tsconfig/strictest": "2.0.2",
"@types/lint-staged": "13.2.1",
"@types/prettier": "2.7.3",
"lage": "1.7.2"
},
"private": true,
"scripts": {
"lage": "lage",
"postinstall": "patch-package"
},
"type": "module",
"workspaces": [
"alfred",
"web",
Expand Down
81 changes: 41 additions & 40 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,63 @@
"version": "1.0.0",
"author": "",
"dependencies": {
"@coobaha/typed-fastify": "^1.0.1",
"@fastify/autoload": "^5.2.0",
"@fastify/caching": "^8.0.1",
"@fastify/cors": "^8.1.0",
"@fastify/etag": "^4.1.0",
"@fastify/formbody": "^7.0.1",
"@fastify/helmet": "^9.1.0",
"@fastify/rate-limit": "^7.3.0",
"@fastify/sensible": "^5.1.0",
"@fastify/swagger": "^7.4.1",
"@coobaha/typed-fastify": "1.2.0",
"@fastify/autoload": "5.8.0",
"@fastify/caching": "8.3.0",
"@fastify/cors": "8.4.0",
"@fastify/etag": "4.2.0",
"@fastify/formbody": "7.4.0",
"@fastify/helmet": "11.1.1",
"@fastify/rate-limit": "8.0.3",
"@fastify/sensible": "5.5.0",
"@fastify/swagger": "8.12.0",
"cheerio": "^1.0.0-rc.12",
"dd-trace": "^2.12.2",
"dompurify": "^2.3.10",
"fastify": "^4.4.0",
"fastify-blipp": "^3.1.0",
"fastify-cli": "^5.0.0",
"fastify-plugin": "^4.1.0",
"got": "11.8.5",
"jsdom": "^20.0.0",
"json5": "^2.2.1",
"mkdirp": "^1.0.4",
"pino": "^8.4.0",
"pino-pretty": "^8.1.0",
"qs": "^6.11.0",
"typescript": "^4.9.4",
"utility-types": "^3.10.0"
"dd-trace": "4.17.0",
"dompurify": "3.0.6",
"fastify": "4.24.3",
"fastify-blipp": "4.0.0",
"fastify-cli": "5.8.0",
"fastify-plugin": "4.5.1",
"got": "13.0.0",
"jsdom": "22.1.0",
"json5": "2.2.3",
"mkdirp": "3.0.1",
"pino": "8.16.1",
"pino-pretty": "10.2.3",
"qs": "6.11.2",
"typescript": "5.2.2",
"utility-types": "3.10.0"
},
"devDependencies": {
"@types/cheerio": "^0.22.31",
"@types/concurrently": "^6.4.0",
"@types/dompurify": "^2.3.3",
"@types/jsdom": "^20.0.0",
"@types/mkdirp": "^1.0.2",
"@types/node": "^18.6.5",
"@types/pino": "^7.0.4",
"@types/prettier": "^2.7.0",
"@types/qs": "^6.9.7",
"@types/tap": "^15.0.7",
"concurrently": "^7.3.0",
"prettier": "^2.7.1",
"tap": "^16.3.0"
"@types/cheerio": "0.22.33",
"@types/dompurify": "3.0.4",
"@types/got": "9.6.12",
"@types/jsdom": "21.1.4",
"@types/node": "20.8.9",
"@types/qs": "6.9.9",
"@types/tap": "15.0.10",
"concurrently": "7.3.0",
"prettier": "3.0.3",
"tap": "16.3.0"
},
"directories": {
"test": "test"
},
"config": {
"enviroment": "production"
},
"keywords": [],
"license": "ISC",
"main": "app.mts",
"private": true,
"type": "module",
"resolutions": {
"ts-json-schema-generator": "0.82.0"
},
"scripts": {
"build:ts": "tsc",
"dev": "tsc && concurrently -k -p \"[{name}]\" -n \"TypeScript,App\" -c \"yellow.bold,cyan.bold\" \"tsc -w\" \"fastify start -o -w --ignore-watch 'client node_modules .idea dist' -l info -P dist/app.cjs\"",
"start": "yarn build:ts && fastify start -o -l info dist/app.js",
"dev": "tsc && concurrently -k -p \"[{name}]\" -n \"TypeScript,App\" -c \"yellow.bold,cyan.bold\" \"tsc -w\" \"fastify start --esm -o -w --ignore-watch 'client node_modules .idea dist' --ignore-watch=.ts$ -l info -P dist/app.js\"",
"start": "yarn build:ts && fastify start --esm -o -l info dist/app.js",
"test": "tsc --noEmit"
}
}
50 changes: 50 additions & 0 deletions server/scratch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as fs from 'node:fs';
import * as cheerio from 'cheerio';
import * as path from 'node:path';
import { fileURLToPath } from 'url';

// @ts-ignore
const __dirname = path.dirname(fileURLToPath(import.meta.url));

const main = async () => {
const html = await fs.promises.readFile(
path.join(__dirname, 'wk.html'),
'utf-8',
);

const finnish = html
.split('<hr />')
.find((section) => section.includes('id="Finnish"'));

if (!finnish) throw new Error('No Finnish section found');
const $$ = cheerio.load(finnish);

const $html = $$.root();
$html.find('#toc').remove();
$html.find('.mw-editsection').remove();
$html.find('*').each((_x, el) => {
const $el = $$(el);
if ($el.attr('lang') !== 'fi') {
$el.removeAttr('lang');
}
if ($el.hasClass('term-list-header')) {
$el.removeClass('term-list-header').addClass('title');
}
if ($el.is('style')) {
$el.remove();
}
});
$html.find('table *').each((_x, el) => {
$$(el).removeAttr('class').removeAttr('lang');
});

let maybeTranslation = $html
.find('.Latn.headword[lang="fi"]')
.closest('p')
.next('ol, ul')
.text();

console.log(maybeTranslation);
};

void main();
47 changes: 25 additions & 22 deletions server/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import './tracer';
import './tracer.js';

import * as path from 'path';
import AutoLoad, { AutoloadPluginOptions } from '@fastify/autoload';
import AutoLoad, { type AutoloadPluginOptions } from '@fastify/autoload';
import type { FastifyPluginAsync, FastifyServerOptions } from 'fastify';
import FastifySensible from '@fastify/sensible';
import * as qs from 'qs';
import FastifyBlipp from 'fastify-blipp';
import fastifySwagger from '@fastify/swagger';
import FastifyRateLimit from '@fastify/rate-limit';
import * as process from 'process';
import { dirname } from 'path';
import { fileURLToPath } from 'url';

export type AppOptions = {
// Place your custom options for app below here.
Expand All @@ -28,29 +29,31 @@ const app: FastifyPluginAsync<AppOptions> = async (
});
}

await fastify.register(FastifyBlipp);
await fastify.register(fastifySwagger, {
swagger: {
// servers: [{ url: 'http://localhost:3000' }],
//
info: {
title: 'Test openapi',
description: 'testing the fastify swagger api',
version: '0.1.0',
},
await fastify.register(import('fastify-blipp'));
if (process.env['NODE_ENV'] !== 'production') {
await fastify.register(fastifySwagger, {
swagger: {
// servers: [{ url: 'http://localhost:3000' }],
//
info: {
title: 'Test openapi',
description: 'testing the fastify swagger api',
version: '0.1.0',
},

// externalDocs: {
// url: 'https://swagger.io',
// description: 'Find more info here',
// },
// consumes: ['application/json'],
// produces: ['application/json'],
},
exposeRoute: process.env['NODE_ENV'] !== 'production',
});
// externalDocs: {
// url: 'https://swagger.io',
// description: 'Find more info here',
// },
// consumes: ['application/json'],
// produces: ['application/json'],
},
});
}

// Do not touch the following lines

const __dirname = dirname(fileURLToPath(import.meta.url));
// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
Expand Down
26 changes: 13 additions & 13 deletions server/src/routes/suomea/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import FastifySensible from '@fastify/sensible';
import FastifyFormbody from '@fastify/formbody';
import addSchema, { asReply, Service } from '@coobaha/typed-fastify';
import * as TFS from '@coobaha/typed-fastify';

import { findImages } from '../../shared/images';
import type { SanakirjaData, SkSearchResult } from '../../shared/types';
import { fetchSk, fetchWiktionary } from '../../shared/search';
import FastifyCaching from '@fastify/caching';
import { findImages } from '../../shared/images.js';
import type { SanakirjaData, SkSearchResult } from '../../shared/types.js';
import { fetchSk, fetchWiktionary } from '../../shared/search.js';
import * as FastifyCaching from '@fastify/caching';

import Etag from '@fastify/etag';

import got from 'got';
import qs from 'qs';
import jsonSchema from './suomea_schema.gen.json';
import type { SuomeaSchema } from './suomea_schema';
import jsonSchema from './suomea_schema.gen.json' assert { type: 'json' };
import type { SuomeaSchema } from './suomea_schema.js';
import type { FastifyPluginCallback } from 'fastify';

const suomeaRoute: FastifyPluginCallback = async (fastify): Promise<void> => {
const service: Service<SuomeaSchema> = {
const service: TFS.Service<SuomeaSchema> = {
'GET /images': async function (request, reply) {
const search = request.query;
const images = await findImages(search.q, request.log);
Expand All @@ -39,7 +39,7 @@ const suomeaRoute: FastifyPluginCallback = async (fastify): Promise<void> => {
if (payload) {
return reply.status(200).send(payload);
} else {
return asReply(reply.notFound());
return TFS.asReply(reply.notFound());
}
},
'GET /sk_search': async (request, reply) => {
Expand Down Expand Up @@ -112,7 +112,7 @@ const suomeaRoute: FastifyPluginCallback = async (fastify): Promise<void> => {

return payload
? reply.status(200).send(payload)
: asReply(reply.notFound());
: TFS.asReply(reply.notFound());
},
'GET /sk_search_with_data': async (request, reply) => {
const search = request.query;
Expand Down Expand Up @@ -179,15 +179,15 @@ const suomeaRoute: FastifyPluginCallback = async (fastify): Promise<void> => {
});
},
};
addSchema(fastify, {
TFS.default.default(fastify, {
jsonSchema,
service,
});
fastify.register(FastifySensible);
fastify.register(FastifyFormbody);
fastify.register(Etag);
fastify.register(FastifyCaching, {
privacy: FastifyCaching.privacy.PRIVATE,
fastify.register(FastifyCaching.default, {
privacy: 'private',
expiresIn: 600,
cacheSegment: 'anki',
});
Expand Down
Loading

0 comments on commit 754da92

Please sign in to comment.