mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-05-01 19:57:22 +09:00
wip
This commit is contained in:
parent
548bf14846
commit
dc0f39c9a1
@ -1,5 +1,5 @@
|
|||||||
import * as iconv from 'iconv-lite';
|
import iconv from 'iconv-lite';
|
||||||
import * as jschardet from 'jschardet';
|
import jschardet from 'jschardet';
|
||||||
|
|
||||||
const regCharset = new RegExp(/charset\s*=\s*["']?([\w-]+)/, 'i');
|
const regCharset = new RegExp(/charset\s*=\s*["']?([\w-]+)/, 'i');
|
||||||
|
|
||||||
|
@ -10,9 +10,9 @@ import { readFileSync } from 'node:fs';
|
|||||||
const _filename = fileURLToPath(import.meta.url);
|
const _filename = fileURLToPath(import.meta.url);
|
||||||
const _dirname = dirname(_filename);
|
const _dirname = dirname(_filename);
|
||||||
|
|
||||||
export let agent: Got.Agents | undefined = undefined;
|
export let agent: Got.Agents = {};
|
||||||
export function setAgent(_agent: Got.Agents) {
|
export function setAgent(_agent: Got.Agents) {
|
||||||
agent = _agent;
|
agent = _agent || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GotOptions = {
|
export type GotOptions = {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import fastify from 'fastify';
|
import fastify from 'fastify';
|
||||||
import { summaly } from '../built/index.js';
|
import { summaly } from '../src/index.js';
|
||||||
import { dirname } from 'node:path';
|
import { dirname } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import {expect, jest, test, describe, beforeEach, afterEach} from '@jest/globals';
|
import {expect, jest, test, describe, beforeEach, afterEach} from '@jest/globals';
|
||||||
@ -33,13 +33,12 @@ process.on('unhandledRejection', console.dir);
|
|||||||
let app: ReturnType<typeof fastify>;
|
let app: ReturnType<typeof fastify>;
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (app) app.close();
|
if (app) return app.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
/* tests below */
|
/* tests below */
|
||||||
|
|
||||||
test('faviconがHTML上で指定されていないが、ルートに存在する場合、正しく設定される', async () => {
|
test('faviconがHTML上で指定されていないが、ルートに存在する場合、正しく設定される', async () => {
|
||||||
console.log('AAAAAAAAAAAAAAAAAAAAAAAA')
|
|
||||||
app = fastify({
|
app = fastify({
|
||||||
logger: true,
|
logger: true,
|
||||||
});
|
});
|
||||||
@ -48,19 +47,17 @@ test('faviconがHTML上で指定されていないが、ルートに存在する
|
|||||||
});
|
});
|
||||||
app.get('/favicon.ico', (_, reply) => reply.status(200));
|
app.get('/favicon.ico', (_, reply) => reply.status(200));
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.icon).toBe(`${host}/favicon.ico`);
|
expect(summary.icon).toBe(`${host}/favicon.ico`);
|
||||||
});
|
});
|
||||||
/*
|
|
||||||
test('faviconがHTML上で指定されていなくて、ルートにも存在しなかった場合 null になる', async () => {
|
test('faviconがHTML上で指定されていなくて、ルートにも存在しなかった場合 null になる', async () => {
|
||||||
app = fastify();
|
app = fastify();
|
||||||
app.get('/', (request, reply) => {
|
app.get('/', (request, reply) => {
|
||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/no-favicon.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/no-favicon.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.icon).toBe(null);
|
expect(summary.icon).toBe(null);
|
||||||
@ -72,7 +69,6 @@ test('titleがcleanupされる', async () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/ditry-title.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/ditry-title.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.title).toBe('Strawberry Pasta');
|
expect(summary.title).toBe('Strawberry Pasta');
|
||||||
@ -89,9 +85,9 @@ describe('Private IP blocking', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/og-title.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/og-title.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
expect(summaly(host)).toThrow();
|
|
||||||
|
expect(() => summaly(host)).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -106,7 +102,6 @@ describe('OGP', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/og-title.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/og-title.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.title).toBe('Strawberry Pasta');
|
expect(summary.title).toBe('Strawberry Pasta');
|
||||||
@ -118,7 +113,6 @@ describe('OGP', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/og-description.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/og-description.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.description).toBe('Strawberry Pasta');
|
expect(summary.description).toBe('Strawberry Pasta');
|
||||||
@ -130,7 +124,6 @@ describe('OGP', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/og-site_name.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/og-site_name.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.sitename).toBe('Strawberry Pasta');
|
expect(summary.sitename).toBe('Strawberry Pasta');
|
||||||
@ -142,7 +135,6 @@ describe('OGP', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/og-image.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/og-image.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.thumbnail).toBe('https://himasaku.net/himasaku.png');
|
expect(summary.thumbnail).toBe('https://himasaku.net/himasaku.png');
|
||||||
@ -156,7 +148,6 @@ describe('TwitterCard', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/twitter-title.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/twitter-title.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.title).toBe('Strawberry Pasta');
|
expect(summary.title).toBe('Strawberry Pasta');
|
||||||
@ -168,7 +159,6 @@ describe('TwitterCard', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/twitter-description.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/twitter-description.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.description).toBe('Strawberry Pasta');
|
expect(summary.description).toBe('Strawberry Pasta');
|
||||||
@ -180,7 +170,6 @@ describe('TwitterCard', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/twitter-image.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/twitter-image.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.thumbnail).toBe('https://himasaku.net/himasaku.png');
|
expect(summary.thumbnail).toBe('https://himasaku.net/himasaku.png');
|
||||||
@ -192,7 +181,6 @@ describe('TwitterCard', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/player-peertube-video.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/player-peertube-video.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.player.url).toBe('https://example.com/embedurl');
|
expect(summary.player.url).toBe('https://example.com/embedurl');
|
||||||
@ -204,7 +192,6 @@ describe('TwitterCard', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/player-pleroma-video.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/player-pleroma-video.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.player.url).toBe('https://example.com/embedurl');
|
expect(summary.player.url).toBe('https://example.com/embedurl');
|
||||||
@ -216,10 +203,8 @@ describe('TwitterCard', () => {
|
|||||||
return reply.send(fs.createReadStream(_dirname + '/htmls/player-pleroma-image.html'));
|
return reply.send(fs.createReadStream(_dirname + '/htmls/player-pleroma-image.html'));
|
||||||
});
|
});
|
||||||
await app.listen({ port });
|
await app.listen({ port });
|
||||||
await app.ready();
|
|
||||||
|
|
||||||
const summary = await summaly(host);
|
const summary = await summaly(host);
|
||||||
expect(summary.player.url).toBe('https://example.com/embedurl');
|
expect(summary.thumbnail).toBe('https://example.com/imageurl');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
|
Loading…
x
Reference in New Issue
Block a user