mirror of
https://github.com/uetchy/namae.git
synced 2025-08-20 01:48:12 +09:00
chore: cosmetic changes
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
|
||||
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
||||
|
||||
interface App {
|
||||
trackId: string
|
||||
trackName: string
|
||||
kind: string
|
||||
version: string
|
||||
price: string
|
||||
trackViewUrl: string
|
||||
trackId: string;
|
||||
trackName: string;
|
||||
kind: string;
|
||||
version: string;
|
||||
price: string;
|
||||
trackViewUrl: string;
|
||||
}
|
||||
|
||||
interface AppStoreResponse {
|
||||
results: App[]
|
||||
results: App[];
|
||||
}
|
||||
|
||||
export default async function handler(
|
||||
req: NowRequest<{ query: string; country: string }>,
|
||||
res: NowResponse
|
||||
req: NowRequest<{query: string; country: string}>,
|
||||
res: NowResponse,
|
||||
) {
|
||||
const { query, country } = req.query
|
||||
const {query, country} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
const term = encodeURIComponent(query)
|
||||
const countryCode = country || 'us'
|
||||
const limit = 10
|
||||
const term = encodeURIComponent(query);
|
||||
const countryCode = country || 'us';
|
||||
const limit = 10;
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://itunes.apple.com/search?media=software&entity=software,iPadSoftware,macSoftware&country=${countryCode}&limit=${limit}&term=${term}`,
|
||||
'GET'
|
||||
)
|
||||
const body: AppStoreResponse = await response.json()
|
||||
'GET',
|
||||
);
|
||||
const body: AppStoreResponse = await response.json();
|
||||
const apps = body.results.map((app) => ({
|
||||
id: app.trackId,
|
||||
name: app.trackName,
|
||||
@@ -40,9 +40,9 @@ export default async function handler(
|
||||
version: app.version,
|
||||
price: app.price,
|
||||
viewURL: app.trackViewUrl,
|
||||
}))
|
||||
send(res, { result: apps || [] })
|
||||
}));
|
||||
send(res, {result: apps || []});
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,21 @@
|
||||
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
|
||||
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
||||
|
||||
export default async function handler(req: NowRequest, res: NowResponse) {
|
||||
const { query } = req.query
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://packages.debian.org/buster/${encodeURIComponent(query)}`,
|
||||
'GET'
|
||||
)
|
||||
const body = await response.text()
|
||||
const availability = body.includes('No such package')
|
||||
send(res, { availability })
|
||||
'GET',
|
||||
);
|
||||
const body = await response.text();
|
||||
const availability = body.includes('No such package');
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +1,30 @@
|
||||
import dns from 'dns'
|
||||
import { send, sendError, NowRequest, NowResponse } from '../util/http'
|
||||
import dns from 'dns';
|
||||
import {send, sendError, NowRequest, NowResponse} from '../util/http';
|
||||
|
||||
function resolvePromise(hostname: string): Promise<string[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
dns.resolve4(hostname, function(err, addresses) {
|
||||
if (err) return reject(err)
|
||||
resolve(addresses)
|
||||
})
|
||||
})
|
||||
if (err) return reject(err);
|
||||
resolve(addresses);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default async function handler(req: NowRequest, res: NowResponse) {
|
||||
const { query } = req.query
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await resolvePromise(query)
|
||||
const availability = response && response.length > 0 ? false : true
|
||||
send(res, { availability })
|
||||
const response = await resolvePromise(query);
|
||||
const availability = response && response.length > 0 ? false : true;
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
if (err.code === 'ENODATA' || err.code === 'ENOTFOUND') {
|
||||
return res.status(200).json({ availability: true })
|
||||
return res.status(200).json({availability: true});
|
||||
}
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +1,18 @@
|
||||
import whois from 'whois-json'
|
||||
import { send, sendError, NowRequest, NowResponse } from '../util/http'
|
||||
import whois from 'whois-json';
|
||||
import {send, sendError, NowRequest, NowResponse} from '../util/http';
|
||||
|
||||
export default async function handler(req: NowRequest, res: NowResponse) {
|
||||
const { query } = req.query
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await whois(query, { follow: 3, verbose: true })
|
||||
const availability = response[0].data.domainName ? false : true
|
||||
send(res, { availability })
|
||||
const response = await whois(query, {follow: 3, verbose: true});
|
||||
const availability = response[0].data.domainName ? false : true;
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
|
@@ -1,25 +1,25 @@
|
||||
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
|
||||
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
||||
|
||||
export default async function handler(req: NowRequest, res: NowResponse) {
|
||||
const { query } = req.query
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
if (
|
||||
!/^[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/.test(
|
||||
query
|
||||
query,
|
||||
)
|
||||
) {
|
||||
return sendError(res, new Error('invalid characters'))
|
||||
return sendError(res, new Error('invalid characters'));
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`https://${query}`)
|
||||
const availability = response.status === 404
|
||||
send(res, { availability })
|
||||
const response = await fetch(`https://${query}`);
|
||||
const availability = response.status === 404;
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
|
@@ -1,22 +1,22 @@
|
||||
import nock from 'nock'
|
||||
import { mockProvider } from '../util/testHelpers'
|
||||
import nock from 'nock';
|
||||
import {mockProvider} from '../util/testHelpers';
|
||||
|
||||
import provider from './existence'
|
||||
import provider from './existence';
|
||||
|
||||
test('return false if name is taken', async () => {
|
||||
const result = await mockProvider(provider, { query: 'github.com/uetchy' })
|
||||
expect(result).toStrictEqual({ availability: false })
|
||||
})
|
||||
const result = await mockProvider(provider, {query: 'github.com/uetchy'});
|
||||
expect(result).toStrictEqual({availability: false});
|
||||
});
|
||||
|
||||
test('return true if name is not taken', async () => {
|
||||
const result = await mockProvider(provider, {
|
||||
query: 'github.com/uetchyasdf',
|
||||
})
|
||||
expect(result).toStrictEqual({ availability: true })
|
||||
})
|
||||
});
|
||||
expect(result).toStrictEqual({availability: true});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
nock('https://github.com:443', { encodedQueryParams: true })
|
||||
nock('https://github.com:443', {encodedQueryParams: true})
|
||||
.head('/uetchyasdf')
|
||||
.reply(404, [], {
|
||||
Date: 'Wed, 14 Aug 2019 10:52:54 GMT',
|
||||
@@ -45,8 +45,8 @@ beforeEach(() => {
|
||||
"default-src 'none'; base-uri 'self'; connect-src 'self'; form-action 'self'; img-src 'self' data:; script-src,'self'; style-src 'unsafe-inline'",
|
||||
'Content-Encoding': 'gzip',
|
||||
'X-GitHub-Request-Id': 'BA06:51D6:125A0F:1A9B4A:5D53E806',
|
||||
})
|
||||
nock('https://github.com:443', { encodedQueryParams: true })
|
||||
});
|
||||
nock('https://github.com:443', {encodedQueryParams: true})
|
||||
.head('/uetchy')
|
||||
.reply(200, [], {
|
||||
Date: 'Wed, 14 Aug 2019 10:43:09 GMT',
|
||||
@@ -77,5 +77,5 @@ beforeEach(() => {
|
||||
"default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' uploads.github.com www.githubstatus.com collector.githubapp.com api.github.com www.google-analytics.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com wss://live.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; frame-src render.githubusercontent.com; img-src 'self' data: github.githubassets.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com; manifest-src 'self'; media-src 'none'; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com",
|
||||
'Content-Encoding': 'gzip',
|
||||
'X-GitHub-Request-Id': 'A922:19B1:AD411:FB69F:5D53E5BC',
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
@@ -1,22 +1,22 @@
|
||||
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
|
||||
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
||||
|
||||
export default async function handler(req: NowRequest, res: NowResponse) {
|
||||
const { query } = req.query
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://api.launchpad.net/devel/ubuntu/+source/${encodeURIComponent(
|
||||
query
|
||||
query,
|
||||
)}`,
|
||||
'GET'
|
||||
)
|
||||
const availability = response.status !== 200
|
||||
send(res, { availability })
|
||||
'GET',
|
||||
);
|
||||
const availability = response.status !== 200;
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +1,17 @@
|
||||
import npmName from 'npm-name'
|
||||
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
|
||||
import npmName from 'npm-name';
|
||||
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
||||
|
||||
export default async function handler(req: NowRequest, res: NowResponse) {
|
||||
const { query } = req.query
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
try {
|
||||
const availability = await npmName(`@${query}`)
|
||||
send(res, { availability })
|
||||
const availability = await npmName(`@${query}`);
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +1,17 @@
|
||||
import npmName from 'npm-name'
|
||||
import { send, sendError, NowRequest, NowResponse } from '../util/http'
|
||||
import npmName from 'npm-name';
|
||||
import {send, sendError, NowRequest, NowResponse} from '../util/http';
|
||||
|
||||
export default async function handler(req: NowRequest, res: NowResponse) {
|
||||
const { query } = req.query
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
try {
|
||||
const availability = await npmName(query)
|
||||
send(res, { availability })
|
||||
const availability = await npmName(query);
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
|
@@ -1,39 +1,39 @@
|
||||
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
|
||||
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
||||
|
||||
const APPLICATION_ID = process.env.NTA_APPLICATION_ID
|
||||
const APPLICATION_ID = process.env.NTA_APPLICATION_ID;
|
||||
|
||||
export default async function handler(
|
||||
req: NowRequest<{ query: string; country: string }>,
|
||||
res: NowResponse
|
||||
req: NowRequest<{query: string; country: string}>,
|
||||
res: NowResponse,
|
||||
) {
|
||||
const { query } = req.query
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
const encodedQuery = encodeURIComponent(
|
||||
query.replace(/[A-Za-z0-9]/g, (str) =>
|
||||
String.fromCharCode(str.charCodeAt(0) + 0xfee0)
|
||||
)
|
||||
)
|
||||
String.fromCharCode(str.charCodeAt(0) + 0xfee0),
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://api.houjin-bangou.nta.go.jp/4/name?id=${APPLICATION_ID}&name=${encodedQuery}&mode=1&target=1&type=02`,
|
||||
'GET'
|
||||
)
|
||||
const body: string[] = (await response.text()).split('\n').slice(0, -1)
|
||||
const header = body.shift()!.split(',')
|
||||
'GET',
|
||||
);
|
||||
const body: string[] = (await response.text()).split('\n').slice(0, -1);
|
||||
const header = body.shift()!.split(',');
|
||||
const result = body.map((csv) => {
|
||||
const entry = csv.split(',').map((item) =>
|
||||
item
|
||||
.replace(/(^"|"$)/g, '')
|
||||
.replace(/[A-Za-z0-9]/g, (str) =>
|
||||
String.fromCharCode(str.charCodeAt(0) - 0xfee0)
|
||||
String.fromCharCode(str.charCodeAt(0) - 0xfee0),
|
||||
)
|
||||
.replace(/ /g, ' ')
|
||||
)
|
||||
.replace(/ /g, ' '),
|
||||
);
|
||||
|
||||
return {
|
||||
index: entry[0],
|
||||
@@ -70,8 +70,8 @@ export default async function handler(
|
||||
excluded: entry[29],
|
||||
processSection: entry[2],
|
||||
modifiedSection: entry[3],
|
||||
}
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
send(res, {
|
||||
meta: {
|
||||
@@ -88,8 +88,8 @@ export default async function handler(
|
||||
englishName: entry.englishName,
|
||||
}))
|
||||
.slice(10) || [],
|
||||
})
|
||||
});
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,23 @@
|
||||
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
|
||||
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
||||
|
||||
export default async function handler(req: NowRequest, res: NowResponse) {
|
||||
const { query } = req.query
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://${encodeURIComponent(query)}.slack.com`
|
||||
)
|
||||
const availability = response.status !== 200
|
||||
send(res, { availability })
|
||||
`https://${encodeURIComponent(query)}.slack.com`,
|
||||
);
|
||||
const availability = response.status !== 200;
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOTFOUND') {
|
||||
send(res, { availability: true })
|
||||
send(res, {availability: true});
|
||||
} else {
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,23 @@
|
||||
import { send, sendError, fetch, NowResponse, NowRequest } from '../util/http'
|
||||
import {send, sendError, fetch, NowResponse, NowRequest} from '../util/http';
|
||||
|
||||
export default async function handler(req: NowRequest, res: NowResponse) {
|
||||
const { query } = req.query
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
return sendError(res, new Error('no query given'));
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://spectrum.chat/${encodeURIComponent(query)}`,
|
||||
'GET'
|
||||
)
|
||||
const body = await response.text()
|
||||
'GET',
|
||||
);
|
||||
const body = await response.text();
|
||||
const availability = body.includes(
|
||||
'You may be trying to view something that is deleted'
|
||||
)
|
||||
send(res, { availability })
|
||||
'You may be trying to view something that is deleted',
|
||||
);
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user