forked from h3poteto/megalodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
209 changed files
with
19,466 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'npm:axios@1.3.6/lib/adapters/http' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export class RequestCanceledError extends Error { | ||
public isCancel: boolean | ||
|
||
constructor(msg: string) { | ||
super(msg) | ||
this.isCancel = true | ||
Object.setPrototypeOf(this, RequestCanceledError) | ||
} | ||
} | ||
|
||
export const isCancel = (value: any): boolean => { | ||
return value && value.isCancel | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const NO_REDIRECT = 'urn:ietf:wg:oauth:2.0:oob' | ||
export const DEFAULT_SCOPE = ['read', 'write', 'follow'] | ||
export const DEFAULT_UA = 'megalodon' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import axios, { AxiosRequestConfig } from 'npm:axios@1.3.6' | ||
import proxyAgent, { ProxyConfig } from './proxy_config.ts' | ||
import { DEFAULT_UA } from './default.ts' | ||
import { NodeinfoError } from './megalodon.ts' | ||
|
||
const NODEINFO_10 = 'http://nodeinfo.diaspora.software/ns/schema/1.0' | ||
const NODEINFO_20 = 'http://nodeinfo.diaspora.software/ns/schema/2.0' | ||
const NODEINFO_21 = 'http://nodeinfo.diaspora.software/ns/schema/2.1' | ||
|
||
type Links = { | ||
links: Array<Link> | ||
} | ||
|
||
type Link = { | ||
href: string | ||
rel: string | ||
} | ||
|
||
type Nodeinfo10 = { | ||
software: Software | ||
metadata: Metadata | ||
} | ||
|
||
type Nodeinfo20 = { | ||
software: Software | ||
metadata: Metadata | ||
} | ||
|
||
type Nodeinfo21 = { | ||
software: Software | ||
metadata: Metadata | ||
} | ||
|
||
type Software = { | ||
name: string | ||
} | ||
|
||
type Metadata = { | ||
upstream?: { | ||
name: string | ||
} | ||
} | ||
|
||
/** | ||
* Detect SNS type. | ||
* Now support Mastodon, Pleroma and Pixelfed. Throws an error when no known platform can be detected. | ||
* | ||
* @param url Base URL of SNS. | ||
* @param proxyConfig Proxy setting, or set false if don't use proxy. | ||
* @return SNS name. | ||
*/ | ||
export const detector = async ( | ||
url: string, | ||
proxyConfig: ProxyConfig | false = false | ||
): Promise<'mastodon' | 'pleroma' | 'misskey' | 'friendica'> => { | ||
let options: AxiosRequestConfig = { | ||
headers: { | ||
'User-Agent': DEFAULT_UA | ||
} | ||
} | ||
if (proxyConfig) { | ||
options = Object.assign(options, { | ||
httpsAgent: proxyAgent(proxyConfig) | ||
}) | ||
} | ||
|
||
const res = await axios.get<Links>(url + '/.well-known/nodeinfo', options) | ||
const link = res.data.links.find(l => l.rel === NODEINFO_20 || l.rel === NODEINFO_21) | ||
if (!link) throw new NodeinfoError('Could not find nodeinfo') | ||
switch (link.rel) { | ||
case NODEINFO_10: { | ||
const res = await axios.get<Nodeinfo10>(link.href, options) | ||
switch (res.data.software.name) { | ||
case 'pleroma': | ||
return 'pleroma' | ||
case 'mastodon': | ||
return 'mastodon' | ||
case 'misskey': | ||
return 'misskey' | ||
case 'friendica': | ||
return 'friendica' | ||
default: | ||
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name === 'mastodon') { | ||
return 'mastodon' | ||
} | ||
throw new NodeinfoError('Unknown SNS') | ||
} | ||
} | ||
case NODEINFO_20: { | ||
const res = await axios.get<Nodeinfo20>(link.href, options) | ||
switch (res.data.software.name) { | ||
case 'pleroma': | ||
return 'pleroma' | ||
case 'mastodon': | ||
return 'mastodon' | ||
case 'misskey': | ||
return 'misskey' | ||
case 'friendica': | ||
return 'friendica' | ||
default: | ||
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name === 'mastodon') { | ||
return 'mastodon' | ||
} | ||
throw new NodeinfoError('Unknown SNS') | ||
} | ||
} | ||
case NODEINFO_21: { | ||
const res = await axios.get<Nodeinfo21>(link.href, options) | ||
switch (res.data.software.name) { | ||
case 'pleroma': | ||
return 'pleroma' | ||
case 'mastodon': | ||
return 'mastodon' | ||
case 'misskey': | ||
return 'misskey' | ||
case 'friendica': | ||
return 'friendica' | ||
default: | ||
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name === 'mastodon') { | ||
return 'mastodon' | ||
} | ||
throw new NodeinfoError('Unknown SNS') | ||
} | ||
} | ||
default: | ||
throw new NodeinfoError('Could not find nodeinfo') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// <reference path="emoji.ts" /> | ||
/// <reference path="source.ts" /> | ||
/// <reference path="field.ts" /> | ||
namespace Entity { | ||
export type Account = { | ||
id: string | ||
username: string | ||
acct: string | ||
display_name: string | ||
locked: boolean | ||
discoverable?: boolean | ||
group: boolean | null | ||
created_at: string | ||
followers_count: number | ||
following_count: number | ||
statuses_count: number | ||
note: string | ||
url: string | ||
avatar: string | ||
avatar_static: string | ||
header: string | ||
header_static: string | ||
emojis: Array<Emoji> | ||
moved: Account | null | ||
fields: Array<Field> | ||
bot: boolean | null | ||
source?: Source | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Entity { | ||
export type Activity = { | ||
week: string | ||
statuses: string | ||
logins: string | ||
registrations: string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Entity { | ||
export type Application = { | ||
name: string | ||
website?: string | null | ||
vapid_key?: string | null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/// <reference path="attachment.ts" /> | ||
namespace Entity { | ||
export type AsyncAttachment = { | ||
id: string | ||
type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' | ||
url: string | null | ||
remote_url: string | null | ||
preview_url: string | ||
text_url: string | null | ||
meta: Meta | null | ||
description: string | null | ||
blurhash: string | null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace Entity { | ||
export type Sub = { | ||
// For Image, Gifv, and Video | ||
width?: number | ||
height?: number | ||
size?: string | ||
aspect?: number | ||
|
||
// For Gifv and Video | ||
frame_rate?: string | ||
|
||
// For Audio, Gifv, and Video | ||
duration?: number | ||
bitrate?: number | ||
} | ||
|
||
export type Focus = { | ||
x: number | ||
y: number | ||
} | ||
|
||
export type Meta = { | ||
original?: Sub | ||
small?: Sub | ||
focus?: Focus | ||
length?: string | ||
duration?: number | ||
fps?: number | ||
size?: string | ||
width?: number | ||
height?: number | ||
aspect?: number | ||
audio_encode?: string | ||
audio_bitrate?: string | ||
audio_channel?: string | ||
} | ||
|
||
export type Attachment = { | ||
id: string | ||
type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' | ||
url: string | ||
remote_url: string | null | ||
preview_url: string | null | ||
text_url: string | null | ||
meta: Meta | null | ||
description: string | null | ||
blurhash: string | null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Entity { | ||
export type Card = { | ||
url: string | ||
title: string | ||
description: string | ||
type: 'link' | 'photo' | 'video' | 'rich' | ||
image?: string | ||
author_name?: string | ||
author_url?: string | ||
provider_name?: string | ||
provider_url?: string | ||
html?: string | ||
width?: number | ||
height?: number | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// <reference path="status.ts" /> | ||
|
||
namespace Entity { | ||
export type Context = { | ||
ancestors: Array<Status> | ||
descendants: Array<Status> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// <reference path="account.ts" /> | ||
/// <reference path="status.ts" /> | ||
|
||
namespace Entity { | ||
export type Conversation = { | ||
id: string | ||
accounts: Array<Account> | ||
last_status: Status | null | ||
unread: boolean | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Entity { | ||
export type Emoji = { | ||
shortcode: string | ||
static_url: string | ||
url: string | ||
visible_in_picker: boolean | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Entity { | ||
export type FeaturedTag = { | ||
id: string | ||
name: string | ||
statuses_count: number | ||
last_status_at: string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Entity { | ||
export type Field = { | ||
name: string | ||
value: string | ||
verified_at: string | null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Entity { | ||
export type Filter = { | ||
id: string | ||
phrase: string | ||
context: Array<FilterContext> | ||
expires_at: string | null | ||
irreversible: boolean | ||
whole_word: boolean | ||
} | ||
|
||
export type FilterContext = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/// <reference path="emoji.ts" /> | ||
/// <reference path="field.ts" /> | ||
|
||
namespace Entity { | ||
export type FollowRequest = { | ||
id: number | ||
username: string | ||
acct: string | ||
display_name: string | ||
locked: boolean | ||
bot: boolean | ||
discoverable?: boolean | ||
group: boolean | ||
created_at: string | ||
note: string | ||
url: string | ||
avatar: string | ||
avatar_static: string | ||
header: string | ||
header_static: string | ||
followers_count: number | ||
following_count: number | ||
statuses_count: number | ||
emojis: Array<Emoji> | ||
fields: Array<Field> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Entity { | ||
export type History = { | ||
day: string | ||
uses: number | ||
accounts: number | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Entity { | ||
export type IdentityProof = { | ||
provider: string | ||
provider_username: string | ||
updated_at: string | ||
proof_url: string | ||
profile_url: string | ||
} | ||
} |
Oops, something went wrong.