├── .github ├── FUNDING.yml └── workflows │ ├── example.yml │ ├── pages.yml │ ├── release.yml │ ├── reviewdog.yml │ └── test.yml ├── .gitignore ├── .prettierrc ├── .tool-versions ├── .yarn └── releases │ └── yarn-4.6.0.cjs ├── .yarnrc.yml ├── CODEOWNERS ├── LICENSE.txt ├── README.md ├── eslint.config.mjs ├── example ├── node-cjs │ ├── package.json │ ├── src │ │ ├── detector.ts │ │ ├── firefish │ │ │ ├── account.ts │ │ │ ├── authorization.ts │ │ │ ├── cancel.ts │ │ │ ├── emojis.ts │ │ │ ├── favourite.ts │ │ │ ├── get_note.ts │ │ │ ├── instance.ts │ │ │ ├── media.ts │ │ │ ├── notification.ts │ │ │ ├── poll.ts │ │ │ ├── post_note.ts │ │ │ ├── relationships.ts │ │ │ ├── search.ts │ │ │ ├── timeline.ts │ │ │ └── web_socket.ts │ │ ├── friendica │ │ │ └── instance.ts │ │ ├── gotosocial │ │ │ ├── authorization.ts │ │ │ ├── instance.ts │ │ │ └── timeline.ts │ │ ├── mastodon │ │ │ ├── authorization.ts │ │ │ ├── cancel.ts │ │ │ ├── favourite.ts │ │ │ ├── get_status.ts │ │ │ ├── instance.ts │ │ │ ├── marker.ts │ │ │ ├── media.ts │ │ │ ├── notification.ts │ │ │ ├── post_status.ts │ │ │ ├── post_status_with_schedule.ts │ │ │ ├── relationship.ts │ │ │ ├── streaming.ts │ │ │ ├── timeline.ts │ │ │ └── unauthorized_streaming.ts │ │ ├── pixelfed │ │ │ ├── authorization.ts │ │ │ ├── instance.ts │ │ │ ├── streaming.ts │ │ │ └── timeline.ts │ │ └── pleroma │ │ │ ├── authorization.ts │ │ │ ├── cancel.ts │ │ │ ├── custom_emoji.ts │ │ │ ├── emoji_reactions.ts │ │ │ ├── favourite.ts │ │ │ ├── get_status.ts │ │ │ ├── instance.ts │ │ │ ├── marker.ts │ │ │ ├── media.ts │ │ │ ├── mentions.ts │ │ │ ├── notification.ts │ │ │ ├── post_status.ts │ │ │ ├── post_status_with_schedule.ts │ │ │ ├── read_notifications.ts │ │ │ ├── relationship.ts │ │ │ ├── subscribe.ts │ │ │ ├── timeline.ts │ │ │ └── web_socket.ts │ ├── test.png │ └── tsconfig.json ├── node-esm │ ├── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── vite │ ├── .gitignore │ ├── index.html │ ├── package.json │ ├── src │ │ ├── main.ts │ │ └── vite-env.d.ts │ ├── tsconfig.json │ └── vite.config.ts └── webpack │ ├── README.md │ ├── docker-compose.yml │ ├── index.html │ ├── package.json │ ├── src │ └── index.ts │ ├── tsconfig.json │ └── webpack.config.js ├── megalodon ├── lib │ ├── cjs │ │ └── package.json │ └── esm │ │ └── package.json ├── package.json ├── src │ ├── axios.d.ts │ ├── cancel.ts │ ├── default.ts │ ├── detector.ts │ ├── entities │ │ ├── account.ts │ │ ├── activity.ts │ │ ├── announcement.ts │ │ ├── application.ts │ │ ├── async_attachment.ts │ │ ├── attachment.ts │ │ ├── card.ts │ │ ├── context.ts │ │ ├── conversation.ts │ │ ├── emoji.ts │ │ ├── featured_tag.ts │ │ ├── field.ts │ │ ├── filter.ts │ │ ├── follow_request.ts │ │ ├── history.ts │ │ ├── identity_proof.ts │ │ ├── instance.ts │ │ ├── list.ts │ │ ├── marker.ts │ │ ├── mention.ts │ │ ├── notification.ts │ │ ├── poll.ts │ │ ├── preferences.ts │ │ ├── push_subscription.ts │ │ ├── reaction.ts │ │ ├── relationship.ts │ │ ├── report.ts │ │ ├── results.ts │ │ ├── role.ts │ │ ├── scheduled_status.ts │ │ ├── source.ts │ │ ├── stats.ts │ │ ├── status.ts │ │ ├── status_params.ts │ │ ├── status_source.ts │ │ ├── tag.ts │ │ ├── token.ts │ │ └── urls.ts │ ├── entity.ts │ ├── filter_context.ts │ ├── firefish.ts │ ├── firefish │ │ ├── api_client.ts │ │ ├── entities │ │ │ ├── announcement.ts │ │ │ ├── app.ts │ │ │ ├── blocking.ts │ │ │ ├── createdNote.ts │ │ │ ├── emoji.ts │ │ │ ├── favorite.ts │ │ │ ├── field.ts │ │ │ ├── file.ts │ │ │ ├── follow.ts │ │ │ ├── followRequest.ts │ │ │ ├── hashtag.ts │ │ │ ├── instance.ts │ │ │ ├── list.ts │ │ │ ├── meta.ts │ │ │ ├── mute.ts │ │ │ ├── note.ts │ │ │ ├── notification.ts │ │ │ ├── poll.ts │ │ │ ├── reaction.ts │ │ │ ├── relation.ts │ │ │ ├── session.ts │ │ │ ├── stats.ts │ │ │ ├── user.ts │ │ │ └── userDetail.ts │ │ ├── entity.ts │ │ ├── notification.ts │ │ ├── oauth.ts │ │ └── web_socket.ts │ ├── friendica.ts │ ├── friendica │ │ ├── api_client.ts │ │ ├── entities │ │ │ ├── account.ts │ │ │ ├── activity.ts │ │ │ ├── application.ts │ │ │ ├── async_attachment.ts │ │ │ ├── attachment.ts │ │ │ ├── card.ts │ │ │ ├── context.ts │ │ │ ├── conversation.ts │ │ │ ├── emoji.ts │ │ │ ├── featured_tag.ts │ │ │ ├── field.ts │ │ │ ├── filter.ts │ │ │ ├── follow_request.ts │ │ │ ├── history.ts │ │ │ ├── identity_proof.ts │ │ │ ├── instance.ts │ │ │ ├── list.ts │ │ │ ├── marker.ts │ │ │ ├── mention.ts │ │ │ ├── notification.ts │ │ │ ├── poll.ts │ │ │ ├── preferences.ts │ │ │ ├── push_subscription.ts │ │ │ ├── relationship.ts │ │ │ ├── report.ts │ │ │ ├── results.ts │ │ │ ├── scheduled_status.ts │ │ │ ├── source.ts │ │ │ ├── stats.ts │ │ │ ├── status.ts │ │ │ ├── status_params.ts │ │ │ ├── status_source.ts │ │ │ ├── tag.ts │ │ │ ├── token.ts │ │ │ └── urls.ts │ │ ├── entity.ts │ │ ├── notification.ts │ │ ├── oauth.ts │ │ └── web_socket.ts │ ├── gotosocial.ts │ ├── gotosocial │ │ ├── api_client.ts │ │ ├── entities │ │ │ ├── account.ts │ │ │ ├── application.ts │ │ │ ├── attachment.ts │ │ │ ├── card.ts │ │ │ ├── context.ts │ │ │ ├── emoji.ts │ │ │ ├── field.ts │ │ │ ├── filter.ts │ │ │ ├── instance.ts │ │ │ ├── list.ts │ │ │ ├── marker.ts │ │ │ ├── mention.ts │ │ │ ├── notification.ts │ │ │ ├── poll.ts │ │ │ ├── preferences.ts │ │ │ ├── relationship.ts │ │ │ ├── report.ts │ │ │ ├── results.ts │ │ │ ├── role.ts │ │ │ ├── scheduled_status.ts │ │ │ ├── source.ts │ │ │ ├── stats.ts │ │ │ ├── status.ts │ │ │ ├── status_params.ts │ │ │ ├── status_source.ts │ │ │ ├── tag.ts │ │ │ ├── token.ts │ │ │ └── urls.ts │ │ ├── entity.ts │ │ ├── notification.ts │ │ ├── oauth.ts │ │ └── web_socket.ts │ ├── index.ts │ ├── mastodon.ts │ ├── mastodon │ │ ├── api_client.ts │ │ ├── entities │ │ │ ├── account.ts │ │ │ ├── activity.ts │ │ │ ├── announcement.ts │ │ │ ├── application.ts │ │ │ ├── async_attachment.ts │ │ │ ├── attachment.ts │ │ │ ├── card.ts │ │ │ ├── context.ts │ │ │ ├── conversation.ts │ │ │ ├── emoji.ts │ │ │ ├── featured_tag.ts │ │ │ ├── field.ts │ │ │ ├── filter.ts │ │ │ ├── history.ts │ │ │ ├── identity_proof.ts │ │ │ ├── instance.ts │ │ │ ├── list.ts │ │ │ ├── marker.ts │ │ │ ├── mention.ts │ │ │ ├── notification.ts │ │ │ ├── poll.ts │ │ │ ├── preferences.ts │ │ │ ├── push_subscription.ts │ │ │ ├── relationship.ts │ │ │ ├── report.ts │ │ │ ├── results.ts │ │ │ ├── role.ts │ │ │ ├── scheduled_status.ts │ │ │ ├── source.ts │ │ │ ├── stats.ts │ │ │ ├── status.ts │ │ │ ├── status_params.ts │ │ │ ├── status_source.ts │ │ │ ├── tag.ts │ │ │ ├── token.ts │ │ │ └── urls.ts │ │ ├── entity.ts │ │ ├── notification.ts │ │ ├── oauth.ts │ │ └── web_socket.ts │ ├── megalodon.ts │ ├── notification.ts │ ├── oauth.ts │ ├── parse_link_header.ts │ ├── parser.ts │ ├── pixelfed.ts │ ├── pixelfed │ │ ├── api_client.ts │ │ ├── entities │ │ │ ├── account.ts │ │ │ ├── announcement.ts │ │ │ ├── application.ts │ │ │ ├── async_attachment.ts │ │ │ ├── attachment.ts │ │ │ ├── context.ts │ │ │ ├── conversation.ts │ │ │ ├── emoji.ts │ │ │ ├── field.ts │ │ │ ├── filter.ts │ │ │ ├── history.ts │ │ │ ├── instance.ts │ │ │ ├── marker.ts │ │ │ ├── mention.ts │ │ │ ├── notification.ts │ │ │ ├── poll.ts │ │ │ ├── preferences.ts │ │ │ ├── relationship.ts │ │ │ ├── report.ts │ │ │ ├── results.ts │ │ │ ├── scheduled_status.ts │ │ │ ├── source.ts │ │ │ ├── stats.ts │ │ │ ├── status.ts │ │ │ ├── status_params.ts │ │ │ ├── tag.ts │ │ │ └── token.ts │ │ ├── entity.ts │ │ ├── notification.ts │ │ ├── oauth.ts │ │ └── web_socket.ts │ ├── pleroma.ts │ ├── pleroma │ │ ├── api_client.ts │ │ ├── entities │ │ │ ├── account.ts │ │ │ ├── activity.ts │ │ │ ├── announcement.ts │ │ │ ├── application.ts │ │ │ ├── async_attachment.ts │ │ │ ├── attachment.ts │ │ │ ├── card.ts │ │ │ ├── context.ts │ │ │ ├── conversation.ts │ │ │ ├── emoji.ts │ │ │ ├── featured_tag.ts │ │ │ ├── field.ts │ │ │ ├── filter.ts │ │ │ ├── history.ts │ │ │ ├── identity_proof.ts │ │ │ ├── instance.ts │ │ │ ├── list.ts │ │ │ ├── marker.ts │ │ │ ├── mention.ts │ │ │ ├── notification.ts │ │ │ ├── poll.ts │ │ │ ├── preferences.ts │ │ │ ├── push_subscription.ts │ │ │ ├── reaction.ts │ │ │ ├── relationship.ts │ │ │ ├── report.ts │ │ │ ├── results.ts │ │ │ ├── scheduled_status.ts │ │ │ ├── source.ts │ │ │ ├── stats.ts │ │ │ ├── status.ts │ │ │ ├── status_params.ts │ │ │ ├── status_source.ts │ │ │ ├── tag.ts │ │ │ ├── token.ts │ │ │ └── urls.ts │ │ ├── entity.ts │ │ ├── notification.ts │ │ ├── oauth.ts │ │ └── web_socket.ts │ └── response.ts ├── test │ ├── integration │ │ ├── cancel.spec.ts │ │ ├── cancelWorker.ts │ │ ├── detector.spec.ts │ │ ├── mastodon.spec.ts │ │ ├── mastodon │ │ │ └── api_client.spec.ts │ │ └── pleroma.spec.ts │ └── unit │ │ ├── firefish │ │ └── api_client.spec.ts │ │ ├── mastodon.spec.ts │ │ ├── mastodon │ │ ├── api_client.spec.ts │ │ └── web_socket.spec.ts │ │ ├── parser.spec.ts │ │ └── pleroma │ │ └── api_client.spec.ts ├── tsconfig.cjs.json ├── tsconfig.esm.json └── tsconfig.test.json ├── migration_guide.md ├── package.json ├── renovate.json └── yarn.lock /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: h3poteto 2 | -------------------------------------------------------------------------------- /.github/workflows/pages.yml: -------------------------------------------------------------------------------- 1 | name: Deploy documents 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | # Allows you to run this workflow manually from the Actions tab 8 | workflow_dispatch: 9 | 10 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 11 | permissions: 12 | contents: read 13 | pages: write 14 | id-token: write 15 | 16 | concurrency: 17 | group: "pages" 18 | cancel-in-progress: false 19 | 20 | jobs: 21 | deploy: 22 | environment: 23 | name: github-pages 24 | url: ${{ steps.deployment.outputs.page_url }} 25 | runs-on: ubuntu-latest 26 | steps: 27 | - name: Checkout 28 | uses: actions/checkout@v4 29 | - name: Use Node.js 22.x 30 | uses: actions/setup-node@v4 31 | with: 32 | node-version: '22.x' 33 | registry-url: 'https://registry.npmjs.org' 34 | - name: Build 35 | run: | 36 | yarn install 37 | yarn workspace megalodon doc 38 | - name: Setup Pages 39 | uses: actions/configure-pages@v5 40 | - name: Upload artifact 41 | uses: actions/upload-pages-artifact@v3 42 | with: 43 | path: './docs' 44 | - name: Deploy to GitHub Pages 45 | id: deployment 46 | uses: actions/deploy-pages@v4 47 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | release: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v4 13 | - name: Use Node.js 22.x 14 | uses: actions/setup-node@v4 15 | with: 16 | node-version: '22.x' 17 | registry-url: 'https://registry.npmjs.org' 18 | - name: Copy README 19 | run: | 20 | cp README.md ./megalodon/ 21 | cp LICENSE.txt ./megalodon/ 22 | - name: Install dependencies 23 | run: | 24 | yarn install 25 | - name: Build 26 | run: | 27 | yarn workspace megalodon run build 28 | # refs: https://github.com/actions/setup-node/issues/942#issuecomment-1920476219 29 | - name: Authentication 30 | run: | 31 | echo npmAuthToken: "$NODE_AUTH_TOKEN" >> ./.yarnrc.yml 32 | env: 33 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 34 | - name: Publish 35 | run: | 36 | yarn workspace megalodon npm publish 37 | 38 | -------------------------------------------------------------------------------- /.github/workflows/reviewdog.yml: -------------------------------------------------------------------------------- 1 | name: reviewdog 2 | 3 | on: 4 | pull_request: 5 | 6 | permissions: 7 | checks: write 8 | contents: read 9 | pull-requests: write 10 | 11 | jobs: 12 | eslint: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@master 17 | - name: Use Node.js 22.x 18 | uses: actions/setup-node@v4 19 | with: 20 | node-version: '22.x' 21 | registry-url: 'https://registry.npmjs.org' 22 | - name: Install dependencies 23 | run: | 24 | yarn install 25 | - uses: reviewdog/action-setup@v1 26 | - name: megalodon eslint 27 | env: 28 | REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} 29 | run: | 30 | yarn workspace megalodon lint | reviewdog -f=eslint -reporter=github-pr-review -fail-on-error=true 31 | - name: example/typescript eslint 32 | env: 33 | REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} 34 | run: | 35 | yarn workspace example lint | reviewdog -f=eslint -reporter=github-pr-review -fail-on-error=true 36 | - name: example/webpack eslint 37 | env: 38 | REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} 39 | run: | 40 | yarn workspace webpack lint | reviewdog -f=eslint -reporter=github-pr-review -fail-on-error=true 41 | - name: example/vite eslint 42 | env: 43 | REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} 44 | run: | 45 | yarn workspace vite lint | reviewdog -f=eslint -reporter=github-pr-review -fail-on-error=true 46 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | tags: 9 | 10 | pull_request: 11 | 12 | jobs: 13 | test: 14 | runs-on: ubuntu-latest 15 | 16 | strategy: 17 | matrix: 18 | node-version: [18.x, 20.x, 22.x] 19 | 20 | steps: 21 | - uses: actions/checkout@v4 22 | - name: Use Node.js ${{ matrix.node-version }} 23 | uses: actions/setup-node@v4 24 | with: 25 | node-version: ${{ matrix.node-version }} 26 | - name: Install dependencies 27 | run: | 28 | yarn install 29 | - name: Build 30 | run: | 31 | yarn workspace megalodon run build 32 | - name: Testing 33 | run: | 34 | yarn workspace megalodon run test 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | !lib/**/package.json 4 | dist 5 | example/typescript/dist 6 | example/webpack/dist 7 | example/vite/dist 8 | docs/ 9 | .env 10 | .yarn/* 11 | !.yarn/releases -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "semi": false, 4 | "singleQuote": true, 5 | "printWidth": 140, 6 | "trailingComma": "none", 7 | "arrowParens": "avoid" 8 | } 9 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | nodejs 22.11.0 2 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | compressionLevel: mixed 2 | 3 | enableGlobalCache: false 4 | 5 | nodeLinker: node-modules 6 | 7 | yarnPath: .yarn/releases/yarn-4.6.0.cjs 8 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @h3poteto 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Akira Fukushima 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "eslint/config"; 2 | import typescriptEslint from "@typescript-eslint/eslint-plugin"; 3 | import prettier from "eslint-plugin-prettier"; 4 | import globals from "globals"; 5 | import tsParser from "@typescript-eslint/parser"; 6 | import path from "node:path"; 7 | import { fileURLToPath } from "node:url"; 8 | import js from "@eslint/js"; 9 | import { FlatCompat } from "@eslint/eslintrc"; 10 | 11 | const __filename = fileURLToPath(import.meta.url); 12 | const __dirname = path.dirname(__filename); 13 | const compat = new FlatCompat({ 14 | baseDirectory: __dirname, 15 | recommendedConfig: js.configs.recommended, 16 | allConfig: js.configs.all 17 | }); 18 | 19 | export default defineConfig([{ 20 | extends: compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"), 21 | 22 | plugins: { 23 | "@typescript-eslint": typescriptEslint, 24 | prettier, 25 | }, 26 | 27 | languageOptions: { 28 | globals: { 29 | ...globals.browser, 30 | ...globals.node, 31 | __static: true, 32 | }, 33 | 34 | parser: tsParser, 35 | ecmaVersion: 5, 36 | sourceType: "module", 37 | 38 | parserOptions: { 39 | project: "./tsconfig.esm.json", 40 | }, 41 | }, 42 | 43 | rules: { 44 | "arrow-parens": 0, 45 | "generator-star-spacing": 0, 46 | "no-debugger": 0, 47 | "no-unused-vars": "off", 48 | "@typescript-eslint/no-empty-object-type": [ 49 | "error", 50 | { "allowObjectTypes": "always" } 51 | ], 52 | "@typescript-eslint/no-unused-vars": ["error", { 53 | argsIgnorePattern: "^_", 54 | }], 55 | camelcase: "off", 56 | "@typescript-eslint/camelcase": "off", 57 | "space-before-function-paren": "off", 58 | "promise/param-names": "off", 59 | "@typescript-eslint/triple-slash-reference": "off", 60 | "@typescript-eslint/no-explicit-any": "off", 61 | "@typescript-eslint/no-namespace": "off", 62 | "prettier/prettier": "error", 63 | }, 64 | }]); -------------------------------------------------------------------------------- /example/node-cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-cjs", 3 | "version": "4.0.0", 4 | "private": true, 5 | "type": "commonjs", 6 | "scripts": { 7 | "build": "tsc -p ./", 8 | "lint": "eslint --ext .js,.ts src" 9 | }, 10 | "author": "h3poteto", 11 | "license": "MIT", 12 | "dependencies": { 13 | "megalodon": "*", 14 | "typescript": "5.4.5" 15 | }, 16 | "devDependencies": { 17 | "@types/node": "^22.9.1", 18 | "eslint": "^9.23.0", 19 | "log4js": "^6.9.1" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/node-cjs/src/detector.ts: -------------------------------------------------------------------------------- 1 | import { detector } from 'megalodon' 2 | 3 | const URL = process.env.URL as string 4 | 5 | detector(URL).then(sns => { 6 | console.log(sns) 7 | }) 8 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/account.ts: -------------------------------------------------------------------------------- 1 | import generator, { MegalodonInterface } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | FIREFISH_ACCESS_TOKEN: string 6 | FIREFISH_URL: string 7 | } 8 | } 9 | 10 | const BASE_URL: string = process.env.FIREFISH_URL 11 | 12 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN 13 | 14 | const client: MegalodonInterface = generator('firefish', BASE_URL, access_token) 15 | 16 | client 17 | .verifyAccountCredentials() 18 | .then(res => console.log(res.data)) 19 | .catch(err => console.error(err)) 20 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/authorization.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import { OAuth, Firefish } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = process.env.FIREFISH_URL! 10 | 11 | let clientId: string 12 | let clientSecret: string 13 | 14 | const client = new Firefish(BASE_URL) 15 | 16 | client 17 | .registerApp('Test App') 18 | .then(appData => { 19 | clientId = appData.client_id 20 | clientSecret = appData.client_secret 21 | console.log('\napp_secret_key:') 22 | console.log('Authorization URL is generated.') 23 | console.log(appData.url) 24 | console.log() 25 | return new Promise(resolve => { 26 | rl.question('Enter any keys after you authorize to firefish: ', _code => { 27 | resolve(appData.session_token) 28 | rl.close() 29 | }) 30 | }) 31 | }) 32 | .then((session_token: string | null) => { 33 | if (!session_token) { 34 | throw new Error('Could not get session token') 35 | } 36 | return client.fetchAccessToken(clientId, clientSecret, session_token) 37 | }) 38 | .then((tokenData: OAuth.TokenData) => { 39 | console.log('\naccess_token:') 40 | console.log(tokenData.access_token) 41 | console.log('\nrefresh_token:') 42 | console.log(tokenData.refresh_token) 43 | console.log() 44 | }) 45 | .catch((err: any) => { 46 | console.error(err) 47 | }) 48 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/cancel.ts: -------------------------------------------------------------------------------- 1 | import generator, { isCancel } from 'megalodon' 2 | 3 | const url: string = process.env.FIREFISH_URL! 4 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 5 | const client = generator('firefish', url, access_token) 6 | 7 | client 8 | .search('h3poteto', { type: 'accounts' }) 9 | .then(res => console.log(res.data)) 10 | .catch(err => { 11 | if (isCancel(err)) { 12 | console.log('Request was canceled') 13 | } 14 | }) 15 | 16 | setTimeout(() => { 17 | client.cancel() 18 | }, 1000) 19 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/emojis.ts: -------------------------------------------------------------------------------- 1 | import generator, { MegalodonInterface } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.FIREFISH_URL! 4 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 5 | 6 | const client: MegalodonInterface = generator('firefish', BASE_URL, access_token) 7 | 8 | client 9 | .getInstanceCustomEmojis() 10 | .then(res => console.log(res.data)) 11 | .catch(err => console.error(err)) 12 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/favourite.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | const BASE_URL = process.env.FIREFISH_URL! 4 | const access_token = process.env.FIREFISH_ACCESS_TOKEN! 5 | const client = generator('firefish', BASE_URL, access_token) 6 | client 7 | .getNotifications() 8 | .then((res: Response>) => { 9 | console.log(res.headers) 10 | console.log(res.data) 11 | }) 12 | .catch(err => console.error(err)) 13 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/get_note.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { MegalodonInterface } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = process.env.FIREFISH_URL! 10 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 11 | 12 | new Promise((resolve, reject) => { 13 | rl.question('NoteID: ', id => { 14 | const client: MegalodonInterface = generator('firefish', BASE_URL, access_token) 15 | 16 | client 17 | .getStatus(id) 18 | .then(res => { 19 | console.log(res.data) 20 | resolve(res) 21 | }) 22 | .catch(err => { 23 | console.error(err) 24 | reject(err) 25 | }) 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/instance.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | const BASE_URL = process.env.FIREFISH_URL! 4 | 5 | const client = generator('firefish', BASE_URL) 6 | 7 | client 8 | .getInstance() 9 | .then((res: Response) => { 10 | console.log(res.data) 11 | }) 12 | .catch(err => console.error(err)) 13 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/media.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | import * as fs from 'fs' 3 | 4 | const BASE_URL: string = process.env.FIREFISH_URL! 5 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 6 | 7 | const client = generator('firefish', BASE_URL, access_token) 8 | 9 | const image = fs.createReadStream('test.png') 10 | 11 | client.uploadMedia(image).then((resp: Response) => { 12 | console.log(resp.data) 13 | }) 14 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/notification.ts: -------------------------------------------------------------------------------- 1 | import generator, { NotificationType } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.FIREFISH_URL! 4 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 5 | 6 | const client = generator('firefish', BASE_URL, access_token) 7 | 8 | client.getNotifications({ exclude_types: [NotificationType.Favourite, NotificationType.Reblog] }).then(res => console.log(res.data)) 9 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/poll.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { Entity, Response } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = process.env.FIREFISH_URL! 10 | 11 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 12 | 13 | const client = generator('firefish', BASE_URL, access_token) 14 | 15 | const options = { 16 | poll: { 17 | options: ['hoge', 'fuga'], 18 | expires_in: 86400, 19 | multiple: false 20 | } 21 | } 22 | 23 | new Promise(resolve => { 24 | rl.question('Toot: ', status => { 25 | client 26 | .postStatus(status, options) 27 | .then((res: Response) => { 28 | console.log(res) 29 | rl.close() 30 | resolve(res) 31 | }) 32 | .catch(err => { 33 | console.error(err) 34 | rl.close() 35 | }) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/post_note.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { Entity, Response } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = process.env.FIREFISH_URL! 10 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 11 | 12 | const client = generator('firefish', BASE_URL, access_token) 13 | 14 | new Promise(resolve => { 15 | rl.question('Toot: ', status => { 16 | client 17 | .postStatus(status) 18 | .then((res: Response) => { 19 | console.log(res) 20 | rl.close() 21 | resolve(res) 22 | }) 23 | .catch(err => { 24 | console.error(err) 25 | rl.close() 26 | }) 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/relationships.ts: -------------------------------------------------------------------------------- 1 | import generator from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.FIREFISH_URL! 4 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 5 | 6 | const client = generator('firefish', BASE_URL, access_token) 7 | 8 | client.getRelationships(['9h6wa44zml', '9jla6fu7d8vyj0ji']).then(res => { 9 | console.log(res.data) 10 | }) 11 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/search.ts: -------------------------------------------------------------------------------- 1 | import generator, { MegalodonInterface } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.FIREFISH_URL! 4 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 5 | 6 | const client: MegalodonInterface = generator('firefish', BASE_URL, access_token) 7 | 8 | client 9 | .search('h3poteto') 10 | .then(res => console.log(res.data)) 11 | .catch(err => console.error(err)) 12 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/timeline.ts: -------------------------------------------------------------------------------- 1 | import generator, { MegalodonInterface, Entity, Response } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.FIREFISH_URL! 4 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 5 | 6 | const client: MegalodonInterface = generator('firefish', BASE_URL, access_token) 7 | 8 | client 9 | .getLocalTimeline() 10 | .then((resp: Response>) => { 11 | console.log(resp.data) 12 | }) 13 | .catch(err => console.error(err)) 14 | -------------------------------------------------------------------------------- /example/node-cjs/src/firefish/web_socket.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity } from 'megalodon' 2 | import log4js from 'log4js' 3 | 4 | const BASE_URL: string = process.env.FIREFISH_URL! 5 | const access_token: string = process.env.FIREFISH_ACCESS_TOKEN! 6 | 7 | const client = generator('firefish', BASE_URL, access_token) 8 | 9 | client.localStreaming().then(stream => { 10 | const logger = log4js.getLogger() 11 | logger.level = 'debug' 12 | stream.on('connect', () => { 13 | logger.debug('connect') 14 | }) 15 | 16 | stream.on('pong', () => { 17 | logger.debug('pong') 18 | }) 19 | 20 | stream.on('update', (status: Entity.Status) => { 21 | logger.debug(status) 22 | }) 23 | 24 | stream.on('notification', (notification: Entity.Notification) => { 25 | logger.debug(notification) 26 | }) 27 | 28 | stream.on('error', (err: Error) => { 29 | console.error(err) 30 | }) 31 | 32 | stream.on('close', () => { 33 | logger.debug('close') 34 | }) 35 | 36 | stream.on('parser-error', (err: Error) => { 37 | console.error(err) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /example/node-cjs/src/friendica/instance.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | const BASE_URL = process.env.FRIENDICA_URL! 4 | 5 | const client = generator('friendica', BASE_URL) 6 | 7 | client 8 | .getInstance() 9 | .then((res: Response) => { 10 | console.log(res.data) 11 | }) 12 | .catch(err => console.error(err)) 13 | -------------------------------------------------------------------------------- /example/node-cjs/src/gotosocial/authorization.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { OAuth } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const SCOPES: Array = ['read', 'write', 'follow'] 10 | const BASE_URL: string = process.env.GOTOSOCIAL_URL! 11 | 12 | let clientId: string 13 | let clientSecret: string 14 | 15 | const client = generator('gotosocial', BASE_URL) 16 | 17 | client 18 | .registerApp('Test App', { 19 | scopes: SCOPES 20 | }) 21 | .then(appData => { 22 | clientId = appData.client_id 23 | clientSecret = appData.client_secret 24 | console.log('Authorization URL is generated.') 25 | console.log(appData.url) 26 | console.log() 27 | return new Promise(resolve => { 28 | rl.question('Enter the authorization code from website: ', code => { 29 | resolve(code) 30 | rl.close() 31 | }) 32 | }) 33 | }) 34 | .then((code: string) => { 35 | return client.fetchAccessToken(clientId, clientSecret, code) 36 | }) 37 | .then((tokenData: OAuth.TokenData) => { 38 | console.log('\naccess_token:') 39 | console.log(tokenData.access_token) 40 | console.log('\nrefresh_token:') 41 | console.log(tokenData.refresh_token) 42 | console.log() 43 | }) 44 | .catch((err: Error) => console.error(err)) 45 | -------------------------------------------------------------------------------- /example/node-cjs/src/gotosocial/instance.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.GOTOSOCIAL_URL! 4 | 5 | const client = generator('gotosocial', BASE_URL) 6 | 7 | client.getInstance().then((res: Response) => { 8 | console.log(res.data) 9 | }) 10 | -------------------------------------------------------------------------------- /example/node-cjs/src/gotosocial/timeline.ts: -------------------------------------------------------------------------------- 1 | import generator, { MegalodonInterface, Entity, Response } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.GOTOSOCIAL_URL! 4 | 5 | const access_token: string = process.env.GOTOSOCIAL_ACCESS_TOKEN! 6 | 7 | const client: MegalodonInterface = generator('gotosocial', BASE_URL, access_token) 8 | 9 | client.getPublicTimeline().then((resp: Response>) => { 10 | console.log(resp.data) 11 | }) 12 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/authorization.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { OAuth } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const SCOPES: Array = ['read', 'write', 'follow'] 10 | const BASE_URL: string = 'https://fedibird.com' 11 | 12 | let clientId: string 13 | let clientSecret: string 14 | 15 | const client = generator('mastodon', BASE_URL) 16 | 17 | client 18 | .registerApp('Test App', { 19 | scopes: SCOPES 20 | }) 21 | .then(appData => { 22 | clientId = appData.client_id 23 | clientSecret = appData.client_secret 24 | console.log('Authorization URL is generated.') 25 | console.log(appData.url) 26 | console.log() 27 | return new Promise(resolve => { 28 | rl.question('Enter the authorization code from website: ', code => { 29 | resolve(code) 30 | rl.close() 31 | }) 32 | }) 33 | }) 34 | .then((code: string) => { 35 | return client.fetchAccessToken(clientId, clientSecret, code) 36 | }) 37 | .then((tokenData: OAuth.TokenData) => { 38 | console.log('\naccess_token:') 39 | console.log(tokenData.access_token) 40 | console.log('\nrefresh_token:') 41 | console.log(tokenData.refresh_token) 42 | console.log() 43 | }) 44 | .catch((err: Error) => console.error(err)) 45 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/cancel.ts: -------------------------------------------------------------------------------- 1 | import generator, { Response, Entity, isCancel } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | MASTODON_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://fedibird.com' 10 | 11 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN 12 | 13 | const client = generator('mastodon', BASE_URL, access_token) 14 | 15 | client 16 | .search('whalebird', { type: 'hashtags', resolve: true }) 17 | .then((resp: Response) => { 18 | console.log(resp.data.hashtags) 19 | }) 20 | .catch((err: Error) => { 21 | if (isCancel(err)) { 22 | console.log('Request was canceled') 23 | } 24 | }) 25 | 26 | setTimeout(() => { 27 | client.cancel() 28 | }, 5000) 29 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/favourite.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | MASTODON_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://fedibird.com' 10 | 11 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN 12 | 13 | const client = generator('mastodon', BASE_URL, access_token) 14 | 15 | client.getFavourites().then((res: Response>) => { 16 | console.log(res.headers) 17 | console.log(res.data) 18 | }) 19 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/get_status.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = process.env.MASTODON_URL! 10 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN! 11 | 12 | new Promise(resolve => { 13 | rl.question('StatusID: ', id => { 14 | const client = generator('mastodon', BASE_URL, access_token) 15 | client.getStatus(id).then(res => { 16 | console.log(res.data) 17 | rl.close() 18 | resolve(res) 19 | }) 20 | }) 21 | }) 22 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/instance.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.MASTODON_URL! 4 | 5 | const client = generator('mastodon', BASE_URL) 6 | 7 | client.getInstance().then((res: Response) => { 8 | console.log(res.data) 9 | }) 10 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/marker.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | MASTODON_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://fedibird.com' 10 | 11 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN 12 | 13 | const client = generator('mastodon', BASE_URL, access_token) 14 | 15 | client.getMarkers(['home', 'notifications']).then((res: Response) => { 16 | console.log(res.data) 17 | }) 18 | 19 | client 20 | .saveMarkers({ home: { last_read_id: '106347765980135935' }, notifications: { last_read_id: '105917259070666683' } }) 21 | .then((res: Response) => { 22 | console.log(res.data) 23 | }) 24 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/media.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | import * as fs from 'fs' 3 | 4 | const BASE_URL: string = 'https://fedibird.com' 5 | 6 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN as string 7 | 8 | const client = generator('mastodon', BASE_URL, access_token) 9 | 10 | const image = fs.createReadStream('test.png') 11 | 12 | client.uploadMedia(image).then((resp: Response) => { 13 | console.log(resp.data) 14 | }) 15 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/notification.ts: -------------------------------------------------------------------------------- 1 | import generator, { NotificationType } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | MASTODON_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://fedibird.com' 10 | 11 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN 12 | 13 | const client = generator('mastodon', BASE_URL, access_token) 14 | 15 | client.getNotifications({ exclude_types: [NotificationType.Favourite, NotificationType.Reblog] }).then(res => console.log(res.data)) 16 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/post_status.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { Entity, Response } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = process.env.MASTODON_URL as string 10 | 11 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN as string 12 | 13 | const client = generator('mastodon', BASE_URL, access_token) 14 | 15 | new Promise(resolve => { 16 | rl.question('Toot: ', status => { 17 | client 18 | .postStatus(status) 19 | .then((res: Response) => { 20 | console.log(res) 21 | rl.close() 22 | resolve(res) 23 | }) 24 | .catch(err => { 25 | console.error(err) 26 | rl.close() 27 | }) 28 | }) 29 | }) 30 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/post_status_with_schedule.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { Entity, Response } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = process.env.MASTODON_URL as string 10 | 11 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN as string 12 | 13 | const client = generator('mastodon', BASE_URL, access_token) 14 | 15 | new Promise(resolve => { 16 | rl.question('Toot: ', status => { 17 | let now = new Date() 18 | now.setMinutes(now.getMinutes() + 6) 19 | client 20 | .postStatus(status, { 21 | scheduled_at: now.toISOString(), 22 | visibility: 'private' 23 | }) 24 | .then((res: Response) => { 25 | console.log(res) 26 | rl.close() 27 | resolve(res) 28 | }) 29 | .catch(err => { 30 | console.error(err) 31 | rl.close() 32 | }) 33 | }) 34 | }) 35 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/relationship.ts: -------------------------------------------------------------------------------- 1 | import generator from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | MASTODON_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://fedibird.com' 10 | 11 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN 12 | 13 | const client = generator('mastodon', BASE_URL, access_token) 14 | 15 | client.getRelationship('1').then(res => { 16 | console.log(res.data) 17 | }) 18 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/streaming.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.MASTODON_URL! 4 | 5 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN! 6 | 7 | const client = generator('mastodon', BASE_URL, access_token) 8 | 9 | client.localStreaming().then(stream => { 10 | stream.on('connect', () => { 11 | console.log('connect') 12 | }) 13 | 14 | stream.on('pong', () => { 15 | console.log('pong') 16 | }) 17 | 18 | stream.on('update', (status: Entity.Status) => { 19 | console.log(status) 20 | }) 21 | 22 | stream.on('notification', (notification: Entity.Notification) => { 23 | console.log(notification) 24 | }) 25 | 26 | stream.on('delete', (id: number) => { 27 | console.log(id) 28 | }) 29 | 30 | stream.on('error', (err: Error) => { 31 | console.error(err) 32 | }) 33 | 34 | stream.on('status_update', (status: Entity.Status) => { 35 | console.log('updated: ', status.url) 36 | }) 37 | 38 | stream.on('heartbeat', () => { 39 | console.log('thump.') 40 | }) 41 | 42 | stream.on('close', () => { 43 | console.log('close') 44 | }) 45 | 46 | stream.on('parser-error', (err: Error) => { 47 | console.error(err) 48 | }) 49 | }) 50 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/timeline.ts: -------------------------------------------------------------------------------- 1 | import generator, { MegalodonInterface, Entity, Response } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | MASTODON_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://fedibird.com' 10 | 11 | const access_token: string = process.env.MASTODON_ACCESS_TOKEN 12 | 13 | const client: MegalodonInterface = generator('mastodon', BASE_URL, access_token) 14 | 15 | client.getPublicTimeline().then((resp: Response>) => { 16 | console.log(resp.data) 17 | }) 18 | -------------------------------------------------------------------------------- /example/node-cjs/src/mastodon/unauthorized_streaming.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | MASTODON_URL: string 6 | } 7 | } 8 | 9 | const url: string = process.env.MASTODON_URL 10 | 11 | const client = generator('mastodon', url) 12 | 13 | client.localStreaming().then(stream => { 14 | stream.on('connect', () => { 15 | console.log('connect') 16 | }) 17 | 18 | stream.on('pong', () => { 19 | console.log('pong') 20 | }) 21 | 22 | stream.on('update', (status: Entity.Status) => { 23 | console.log(status) 24 | }) 25 | 26 | stream.on('notification', (notification: Entity.Notification) => { 27 | console.log(notification) 28 | }) 29 | 30 | stream.on('delete', (id: number) => { 31 | console.log(id) 32 | }) 33 | 34 | stream.on('error', (err: Error) => { 35 | console.error(err) 36 | }) 37 | 38 | stream.on('status_update', (status: Entity.Status) => { 39 | console.log('updated: ', status.url) 40 | }) 41 | 42 | stream.on('heartbeat', () => { 43 | console.log('thump.') 44 | }) 45 | 46 | stream.on('close', () => { 47 | console.log('close') 48 | }) 49 | 50 | stream.on('parser-error', (err: Error) => { 51 | console.error(err) 52 | }) 53 | }) 54 | -------------------------------------------------------------------------------- /example/node-cjs/src/pixelfed/authorization.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { OAuth } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const SCOPES: Array = ['read', 'write', 'follow'] 10 | const BASE_URL: string = process.env.PIXELFED_URL! 11 | 12 | let clientId: string 13 | let clientSecret: string 14 | 15 | const client = generator('pixelfed', BASE_URL) 16 | 17 | client 18 | .registerApp('Test App', { 19 | scopes: SCOPES 20 | }) 21 | .then(appData => { 22 | clientId = appData.client_id 23 | clientSecret = appData.client_secret 24 | console.log('Authorization URL is generated.') 25 | console.log(appData.url) 26 | console.log() 27 | return new Promise(resolve => { 28 | rl.question('Enter the authorization code from website: ', code => { 29 | resolve(code) 30 | rl.close() 31 | }) 32 | }) 33 | }) 34 | .then((code: string) => { 35 | return client.fetchAccessToken(clientId, clientSecret, code) 36 | }) 37 | .then((tokenData: OAuth.TokenData) => { 38 | console.log('\naccess_token:') 39 | console.log(tokenData.access_token) 40 | console.log('\nrefresh_token:') 41 | console.log(tokenData.refresh_token) 42 | console.log() 43 | }) 44 | .catch((err: Error) => console.error(err)) 45 | -------------------------------------------------------------------------------- /example/node-cjs/src/pixelfed/instance.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.PIXELFED_URL! 4 | 5 | const client = generator('pixelfed', BASE_URL) 6 | 7 | client.getInstance().then((res: Response) => { 8 | console.log(res.data) 9 | }) 10 | -------------------------------------------------------------------------------- /example/node-cjs/src/pixelfed/streaming.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.PIXELFED_URL! 4 | 5 | const access_token: string = process.env.PIXELFED_ACCESS_TOKEN! 6 | 7 | const client = generator('pixelfed', BASE_URL, access_token) 8 | 9 | client.localStreaming().then(stream => { 10 | stream.on('connect', () => { 11 | console.log('connect') 12 | }) 13 | 14 | stream.on('pong', () => { 15 | console.log('pong') 16 | }) 17 | 18 | stream.on('update', (status: Entity.Status) => { 19 | console.log(status) 20 | }) 21 | 22 | stream.on('notification', (notification: Entity.Notification) => { 23 | console.log(notification) 24 | }) 25 | 26 | stream.on('delete', (id: number) => { 27 | console.log(id) 28 | }) 29 | 30 | stream.on('error', (err: Error) => { 31 | console.error(err) 32 | }) 33 | 34 | stream.on('status_update', (status: Entity.Status) => { 35 | console.log('updated: ', status.url) 36 | }) 37 | 38 | stream.on('heartbeat', () => { 39 | console.log('thump.') 40 | }) 41 | 42 | stream.on('close', () => { 43 | console.log('close') 44 | }) 45 | 46 | stream.on('parser-error', (err: Error) => { 47 | console.error(err) 48 | }) 49 | }) 50 | -------------------------------------------------------------------------------- /example/node-cjs/src/pixelfed/timeline.ts: -------------------------------------------------------------------------------- 1 | import generator, { MegalodonInterface, Entity, Response } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.PIXELFED_URL! 4 | 5 | const access_token: string = process.env.PIXELFED_ACCESS_TOKEN! 6 | 7 | const client: MegalodonInterface = generator('pixelfed', BASE_URL, access_token) 8 | 9 | client.getPublicTimeline().then((resp: Response>) => { 10 | console.log(resp.data) 11 | }) 12 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/authorization.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { OAuth } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const SCOPES: Array = ['read', 'write', 'follow'] 10 | const BASE_URL: string = 'https://pleroma.io' 11 | 12 | let clientId: string 13 | let clientSecret: string 14 | 15 | const client = generator('pleroma', BASE_URL) 16 | 17 | client 18 | .registerApp('Test App', { 19 | scopes: SCOPES 20 | }) 21 | .then(appData => { 22 | clientId = appData.client_id 23 | clientSecret = appData.client_secret 24 | console.log('Authorization URL is generated.') 25 | console.log(appData.url) 26 | console.log() 27 | return new Promise(resolve => { 28 | rl.question('Enter the authorization code from website: ', code => { 29 | resolve(code) 30 | rl.close() 31 | }) 32 | }) 33 | }) 34 | .then((code: string) => { 35 | return client.fetchAccessToken(clientId, clientSecret, code) 36 | }) 37 | .then((tokenData: OAuth.TokenData) => { 38 | console.log('\naccess_token:') 39 | console.log(tokenData.access_token) 40 | console.log('\nrefresh_token:') 41 | console.log(tokenData.refresh_token) 42 | console.log() 43 | }) 44 | .catch((err: Error) => console.error(err)) 45 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/cancel.ts: -------------------------------------------------------------------------------- 1 | import generator, { Response, Entity, isCancel } from 'megalodon' 2 | 3 | const BASE_URL: string = 'https://pleroma.io' 4 | 5 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN! 6 | 7 | const client = generator('pleroma', BASE_URL, access_token) 8 | 9 | client 10 | .search('whalebird', { resolve: true }) 11 | .then((resp: Response) => { 12 | console.log(resp.data.hashtags) 13 | }) 14 | .catch((err: Error) => { 15 | if (isCancel(err)) { 16 | console.log('Request was canceled') 17 | } 18 | }) 19 | 20 | setTimeout(() => { 21 | client.cancel() 22 | }, 5000) 23 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/custom_emoji.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { Entity, Response } from 'megalodon' 3 | 4 | declare var process: { 5 | env: { 6 | PLEROMA_ACCESS_TOKEN: string 7 | } 8 | stdin: any 9 | stdout: any 10 | } 11 | 12 | const rl: readline.ReadLine = readline.createInterface({ 13 | input: process.stdin, 14 | output: process.stdout 15 | }) 16 | 17 | const BASE_URL: string = 'https://pleroma.io' 18 | 19 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN 20 | 21 | const client = generator('pleroma', BASE_URL, access_token) 22 | 23 | rl.question(`Enter status id of ${BASE_URL}: `, id => { 24 | client.createEmojiReaction(id, 'arch_linux').then((res: Response) => { 25 | console.log(res.data) 26 | rl.close() 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/emoji_reactions.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { Entity, Response } from 'megalodon' 3 | 4 | declare var process: { 5 | env: { 6 | PLEROMA_ACCESS_TOKEN: string 7 | } 8 | stdin: any 9 | stdout: any 10 | } 11 | 12 | const rl: readline.ReadLine = readline.createInterface({ 13 | input: process.stdin, 14 | output: process.stdout 15 | }) 16 | 17 | const BASE_URL: string = 'https://pleroma.io' 18 | 19 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN 20 | 21 | const client = generator('pleroma', BASE_URL, access_token) 22 | 23 | rl.question(`Enter status id of ${BASE_URL}: `, id => { 24 | client.createEmojiReaction(id, '😐').then((res: Response) => { 25 | console.log(res.data) 26 | rl.close() 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/favourite.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | PLEROMA_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://pleroma.io' 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN 12 | 13 | const client = generator('pleroma', BASE_URL, access_token) 14 | 15 | client.getFavourites().then((res: Response>) => { 16 | console.log(res.headers) 17 | console.log(res.data) 18 | }) 19 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/get_status.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = process.env.PLEROMA_URL! 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN! 12 | 13 | new Promise(resolve => { 14 | rl.question('StatusID: ', id => { 15 | const client = generator('pleroma', BASE_URL, access_token) 16 | client.getStatus(id).then(res => { 17 | console.log(res.data) 18 | rl.close() 19 | resolve(res) 20 | }) 21 | }) 22 | }) 23 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/instance.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.PLEROMA_URL! 4 | 5 | const client = generator('pleroma', BASE_URL) 6 | 7 | client.getInstance().then((res: Response) => { 8 | console.log(res.data) 9 | }) 10 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/marker.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | PLEROMA_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://pleroma.io' 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN 12 | 13 | const client = generator('pleroma', BASE_URL, access_token) 14 | 15 | client.getMarkers(['home', 'notifications']).then((res: Response>) => { 16 | console.log(res.data) 17 | }) 18 | 19 | // client 20 | // .saveMarkers({ home: { last_read_id: 'A88wHq4Mwbg8vUOvo0' }, notifications: { last_read_id: '7056' } }) 21 | // .then((res: Response) => { 22 | // console.log(res.data) 23 | // }) 24 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/media.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | import * as fs from 'fs' 3 | 4 | const BASE_URL: string = 'https://pleroma.io' 5 | 6 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN as string 7 | 8 | const client = generator('pleroma', BASE_URL, access_token) 9 | 10 | const image = fs.createReadStream('test.png') 11 | 12 | client.uploadMedia(image).then((resp: Response) => { 13 | console.log(resp.data) 14 | }) 15 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/mentions.ts: -------------------------------------------------------------------------------- 1 | import generator, { NotificationType } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | PLEROMA_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://pleroma.io' 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN 12 | 13 | const client = generator('pleroma', BASE_URL, access_token) 14 | 15 | const excludes: Array = [ 16 | NotificationType.Follow, 17 | NotificationType.Favourite, 18 | NotificationType.Reblog, 19 | NotificationType.PollVote, 20 | NotificationType.PollExpired, 21 | NotificationType.Reaction 22 | ] 23 | 24 | client.getNotifications({ min_id: '9318', limit: 30, exclude_types: excludes }).then(res => console.log(res.data)) 25 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/notification.ts: -------------------------------------------------------------------------------- 1 | import generator, { NotificationType } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | PLEROMA_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://pleroma.io' 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN 12 | 13 | const client = generator('pleroma', BASE_URL, access_token) 14 | 15 | client.getNotifications({ exclude_types: [NotificationType.Reblog] }).then(res => console.log(res.data)) 16 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/post_status.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { Entity, Response } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = process.env.PLEROMA_URL as string 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN as string 12 | 13 | const client = generator('pleroma', BASE_URL, access_token) 14 | 15 | new Promise(resolve => { 16 | rl.question('Toot: ', status => { 17 | client 18 | .postStatus(status) 19 | .then((res: Response) => { 20 | console.log(res) 21 | rl.close() 22 | resolve(res) 23 | }) 24 | .catch(err => { 25 | console.error(err) 26 | rl.close() 27 | }) 28 | }) 29 | }) 30 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/post_status_with_schedule.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { Entity, Response } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = process.env.PLEROMA_URL as string 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN as string 12 | 13 | const client = generator('pleroma', BASE_URL, access_token) 14 | 15 | new Promise(resolve => { 16 | rl.question('Toot: ', status => { 17 | let now = new Date() 18 | now.setMinutes(now.getMinutes() + 6) 19 | client 20 | .postStatus(status, { 21 | scheduled_at: now.toISOString(), 22 | visibility: 'private' 23 | }) 24 | .then((res: Response) => { 25 | console.log(res) 26 | rl.close() 27 | resolve(res) 28 | }) 29 | .catch(err => { 30 | console.error(err) 31 | rl.close() 32 | }) 33 | }) 34 | }) 35 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/read_notifications.ts: -------------------------------------------------------------------------------- 1 | import * as readline from 'readline' 2 | import generator, { Entity, Response } from 'megalodon' 3 | 4 | const rl: readline.ReadLine = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }) 8 | 9 | const BASE_URL: string = 'https://pleroma.io' 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN as string 12 | 13 | const client = generator('pleroma', BASE_URL, access_token) 14 | 15 | new Promise(resolve => { 16 | rl.question('Max notification ID: ', max_id => { 17 | client 18 | .readNotifications({ max_id: max_id }) 19 | .then(res => { 20 | console.log(res) 21 | rl.close() 22 | client.getMarkers(['home', 'notifications']).then((res: Response>) => { 23 | console.log(res.data) 24 | }) 25 | 26 | resolve(res) 27 | }) 28 | .catch(err => { 29 | console.error(err) 30 | rl.close() 31 | }) 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/relationship.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | PLEROMA_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://pleroma.io' 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN 12 | 13 | const client = generator('pleroma', BASE_URL, access_token) 14 | 15 | client.getRelationship('3').then((res: Response) => { 16 | console.log(res.data) 17 | }) 18 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/subscribe.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity, Response } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | PLEROMA_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://pleroma.io' 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN 12 | 13 | const client = generator('pleroma', BASE_URL, access_token) 14 | 15 | client.subscribeAccount('3').then((res: Response) => { 16 | console.log(res.data) 17 | }) 18 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/timeline.ts: -------------------------------------------------------------------------------- 1 | import generator, { MegalodonInterface, Entity, Response } from 'megalodon' 2 | 3 | declare var process: { 4 | env: { 5 | PLEROMA_ACCESS_TOKEN: string 6 | } 7 | } 8 | 9 | const BASE_URL: string = 'https://pleroma.io' 10 | 11 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN 12 | 13 | const client: MegalodonInterface = generator('pleroma', BASE_URL, access_token) 14 | 15 | client.getPublicTimeline().then((resp: Response>) => { 16 | console.log(resp.data) 17 | }) 18 | -------------------------------------------------------------------------------- /example/node-cjs/src/pleroma/web_socket.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity } from 'megalodon' 2 | import log4js from 'log4js' 3 | 4 | declare var process: { 5 | env: { 6 | PLEROMA_ACCESS_TOKEN: string 7 | } 8 | } 9 | 10 | const BASE_URL: string = 'https://pleroma.io' 11 | 12 | const access_token: string = process.env.PLEROMA_ACCESS_TOKEN 13 | 14 | const client = generator('pleroma', BASE_URL, access_token) 15 | 16 | client.userStreaming().then(stream => { 17 | const logger = log4js.getLogger() 18 | logger.level = 'debug' 19 | stream.on('connect', () => { 20 | logger.debug('connect') 21 | }) 22 | 23 | stream.on('pong', () => { 24 | logger.debug('pong') 25 | }) 26 | 27 | stream.on('update', (status: Entity.Status) => { 28 | logger.debug(status.url) 29 | }) 30 | 31 | stream.on('notification', (notification: Entity.Notification) => { 32 | logger.debug(notification) 33 | }) 34 | 35 | stream.on('delete', (id: number) => { 36 | logger.debug(id) 37 | }) 38 | 39 | stream.on('error', (err: Error) => { 40 | console.error(err) 41 | }) 42 | 43 | stream.on('heartbeat', () => { 44 | logger.debug('thump.') 45 | }) 46 | 47 | stream.on('status_update', (status: Entity.Status) => { 48 | logger.debug('updated: ', status.url) 49 | }) 50 | 51 | stream.on('close', () => { 52 | logger.debug('close') 53 | }) 54 | 55 | stream.on('parser-error', (err: Error) => { 56 | logger.error(err) 57 | }) 58 | }) 59 | -------------------------------------------------------------------------------- /example/node-cjs/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h3poteto/megalodon/26e207daf65807fdecfd9389184b8081e8737f77/example/node-cjs/test.png -------------------------------------------------------------------------------- /example/node-esm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-esm", 3 | "version": "4.0.0", 4 | "private": true, 5 | "type": "module", 6 | "scripts": { 7 | "build": "tsc -p ./", 8 | "lint": "eslint --ext .js,.ts src" 9 | }, 10 | "author": "h3poteto", 11 | "license": "MIT", 12 | "dependencies": { 13 | "megalodon": "*", 14 | "typescript": "5.4.5" 15 | }, 16 | "devDependencies": { 17 | "@types/node": "^22.9.1", 18 | "eslint": "^9.23.0", 19 | "log4js": "^6.9.1" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/node-esm/src/index.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.MASTODON_URL! 4 | const ACCESS_TOKEN: string = process.env.MASTODON_ACCESS_TOKEN! 5 | console.log(BASE_URL) 6 | console.log('start') 7 | 8 | const client = generator('mastodon', BASE_URL, ACCESS_TOKEN) 9 | 10 | client.publicStreaming().then(stream => { 11 | stream.on('connect', () => { 12 | console.log('connect') 13 | }) 14 | 15 | stream.on('pong', () => { 16 | console.log('pong') 17 | }) 18 | 19 | stream.on('update', (status: Entity.Status) => { 20 | console.log(status) 21 | }) 22 | 23 | stream.on('notification', (notification: Entity.Notification) => { 24 | console.log(notification) 25 | }) 26 | 27 | stream.on('delete', (id: number) => { 28 | console.log(id) 29 | }) 30 | 31 | stream.on('error', (err: Error) => { 32 | console.error(err) 33 | }) 34 | 35 | stream.on('status_update', (status: Entity.Status) => { 36 | console.log('updated: ', status.url) 37 | }) 38 | 39 | stream.on('heartbeat', () => { 40 | console.log('thump.') 41 | }) 42 | 43 | stream.on('close', () => { 44 | console.log('close') 45 | }) 46 | 47 | stream.on('parser-error', (err: Error) => { 48 | console.error(err) 49 | }) 50 | 51 | setTimeout(() => { 52 | stream.removeAllListeners() 53 | stream.stop() 54 | console.log('closed') 55 | }, 100000) 56 | }) 57 | -------------------------------------------------------------------------------- /example/vite/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /example/vite/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + TS 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/vite/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc && vite build", 9 | "preview": "vite preview", 10 | "lint": "eslint --ext .js,.ts src" 11 | }, 12 | "dependencies": { 13 | "megalodon": "*" 14 | }, 15 | "devDependencies": { 16 | "eslint": "^9.23.0", 17 | "typescript": "^5.4.5", 18 | "vite": "^4.4.5" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example/vite/src/main.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity } from 'megalodon' 2 | 3 | const BASE_URL: string = import.meta.env.VITE_MASTODON_URL 4 | const ACCESS_TOKEN: string = import.meta.env.VITE_MASTODON_ACCESS_TOKEN 5 | console.log(BASE_URL) 6 | console.log('start') 7 | 8 | const client = generator('mastodon', BASE_URL, ACCESS_TOKEN) 9 | 10 | client.publicStreaming().then(stream => { 11 | stream.on('connect', () => { 12 | console.log('connect') 13 | }) 14 | 15 | stream.on('pong', () => { 16 | console.log('pong') 17 | }) 18 | 19 | stream.on('update', (status: Entity.Status) => { 20 | console.log(status) 21 | }) 22 | 23 | stream.on('notification', (notification: Entity.Notification) => { 24 | console.log(notification) 25 | }) 26 | 27 | stream.on('delete', (id: number) => { 28 | console.log(id) 29 | }) 30 | 31 | stream.on('error', (err: Error) => { 32 | console.error(err) 33 | }) 34 | 35 | stream.on('status_update', (status: Entity.Status) => { 36 | console.log('updated: ', status.url) 37 | }) 38 | 39 | stream.on('heartbeat', () => { 40 | console.log('thump.') 41 | }) 42 | 43 | stream.on('close', () => { 44 | console.log('close') 45 | }) 46 | 47 | stream.on('parser-error', (err: Error) => { 48 | console.error(err) 49 | }) 50 | // 51 | // setTimeout(() => { 52 | // stream.removeAllListeners() 53 | // stream.stop() 54 | // console.log('closed') 55 | // }, 10000) 56 | }) 57 | -------------------------------------------------------------------------------- /example/vite/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /example/vite/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "noEmit": true, 15 | 16 | /* Linting */ 17 | "strict": true, 18 | "noUnusedLocals": true, 19 | "noUnusedParameters": true, 20 | "noFallthroughCasesInSwitch": true 21 | }, 22 | "include": ["src"] 23 | } 24 | -------------------------------------------------------------------------------- /example/vite/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | 3 | // https://vitejs.dev/config/ 4 | export default defineConfig({ 5 | define: { 6 | 'process.env.NODE_DEBUG': false 7 | } 8 | }) 9 | -------------------------------------------------------------------------------- /example/webpack/README.md: -------------------------------------------------------------------------------- 1 | At first, set environment vairables 2 | 3 | ``` 4 | $ export MASTODON_URL=wss://mastodon.social 5 | $ export MASTODON_ACCESS_TOKEN=foobar 6 | ``` 7 | And execute 8 | 9 | ``` 10 | $ yarn workspace megalodon build 11 | $ yarn workspace browser build 12 | $ yarn workspace browser start 13 | ``` 14 | 15 | Let's open `http://127.0.0.1:8000`. 16 | -------------------------------------------------------------------------------- /example/webpack/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.0' 2 | 3 | services: 4 | node: 5 | image: node:22.11.0-alpine 6 | working_dir: /var/opt/app 7 | volumes: 8 | - .:/var/opt/app 9 | - ../../:/var/opt/megalodon 10 | ports: 11 | - "8000:8000" 12 | command: /bin/sh 13 | -------------------------------------------------------------------------------- /example/webpack/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Megalodon 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /example/webpack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack", 3 | "version": "4.0.0", 4 | "private": true, 5 | "scripts": { 6 | "build": "webpack", 7 | "start": "http-server -p 8000 -s index.html", 8 | "lint": "eslint --ext .js,.ts src" 9 | }, 10 | "author": "Akira Fukushima (https://github.com/h3poteto)", 11 | "license": "MIT", 12 | "dependencies": { 13 | "megalodon": "*" 14 | }, 15 | "devDependencies": { 16 | "eslint": "^9.23.0", 17 | "http-server": "^14.1.1", 18 | "ts-loader": "^9.5.1", 19 | "typescript": "5.4.5", 20 | "webpack": "^5.88.2", 21 | "webpack-cli": "^6.0.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/webpack/src/index.ts: -------------------------------------------------------------------------------- 1 | import generator, { Entity } from 'megalodon' 2 | 3 | const BASE_URL: string = process.env.MASTODON_URL! 4 | const ACCESS_TOKEN: string = process.env.MASTODON_ACCESS_TOKEN! 5 | console.log(BASE_URL) 6 | console.log('start') 7 | 8 | const client = generator('mastodon', BASE_URL, ACCESS_TOKEN) 9 | 10 | client.publicStreaming().then(stream => { 11 | stream.on('connect', () => { 12 | console.log('connect') 13 | }) 14 | 15 | stream.on('pong', () => { 16 | console.log('pong') 17 | }) 18 | 19 | stream.on('update', (status: Entity.Status) => { 20 | console.log(status) 21 | }) 22 | 23 | stream.on('notification', (notification: Entity.Notification) => { 24 | console.log(notification) 25 | }) 26 | 27 | stream.on('delete', (id: number) => { 28 | console.log(id) 29 | }) 30 | 31 | stream.on('error', (err: Error) => { 32 | console.error(err) 33 | }) 34 | 35 | stream.on('status_update', (status: Entity.Status) => { 36 | console.log('updated: ', status.url) 37 | }) 38 | 39 | stream.on('heartbeat', () => { 40 | console.log('thump.') 41 | }) 42 | 43 | stream.on('close', () => { 44 | console.log('close') 45 | }) 46 | 47 | stream.on('parser-error', (err: Error) => { 48 | console.error(err) 49 | }) 50 | 51 | setTimeout(() => { 52 | stream.removeAllListeners() 53 | stream.stop() 54 | console.log('closed') 55 | }, 100000) 56 | }) 57 | -------------------------------------------------------------------------------- /example/webpack/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var webpack = require('webpack') 3 | 4 | module.exports = { 5 | entry: './src/index.ts', 6 | output: { 7 | filename: 'main.js', 8 | path: path.resolve(__dirname, 'dist') 9 | }, 10 | mode: 'development', 11 | devtool: 'source-map', 12 | resolve: { 13 | extensions: ['.ts', '.js'] 14 | }, 15 | module: { 16 | rules: [ 17 | { 18 | test: /\.ts$/, 19 | loader: 'ts-loader' 20 | } 21 | ] 22 | }, 23 | plugins: [ 24 | new webpack.DefinePlugin({ 25 | 'process.env.NODE_DEBUG': false, 26 | 'process.env.MASTODON_URL': `"${process.env.MASTODON_URL}"`, 27 | 'process.env.MASTODON_ACCESS_TOKEN': `"${process.env.MASTODON_ACCESS_TOKEN}"` 28 | }) 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /megalodon/lib/cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs" 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/lib/esm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/src/axios.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'axios/lib/adapters/http' 2 | -------------------------------------------------------------------------------- /megalodon/src/cancel.ts: -------------------------------------------------------------------------------- 1 | export class RequestCanceledError extends Error { 2 | public isCancel: boolean 3 | 4 | constructor(msg: string) { 5 | super(msg) 6 | this.isCancel = true 7 | Object.setPrototypeOf(this, RequestCanceledError) 8 | } 9 | } 10 | 11 | export const isCancel = (value: any): boolean => { 12 | return value && value.isCancel 13 | } 14 | -------------------------------------------------------------------------------- /megalodon/src/default.ts: -------------------------------------------------------------------------------- 1 | export const NO_REDIRECT = 'urn:ietf:wg:oauth:2.0:oob' 2 | export const DEFAULT_SCOPE = ['read', 'write', 'follow'] 3 | export const DEFAULT_UA = 'megalodon' 4 | 5 | export function isBrowser() { 6 | if (typeof window !== 'undefined') { 7 | return true 8 | } else { 9 | return false 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /megalodon/src/entities/account.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | import { Field } from './field.js' 3 | import { Source } from './source.js' 4 | import { Role } from './role.js' 5 | 6 | export type Account = { 7 | id: string 8 | username: string 9 | acct: string 10 | display_name: string 11 | locked: boolean 12 | discoverable?: boolean 13 | group: boolean | null 14 | noindex: boolean | null 15 | suspended: boolean | null 16 | limited: boolean | null 17 | created_at: string 18 | followers_count: number 19 | following_count: number 20 | statuses_count: number 21 | note: string 22 | url: string 23 | avatar: string 24 | avatar_static: string 25 | header: string 26 | header_static: string 27 | emojis: Array 28 | moved: Account | null 29 | fields: Array 30 | bot: boolean | null 31 | source?: Source 32 | role?: Role 33 | mute_expires_at?: string 34 | } 35 | -------------------------------------------------------------------------------- /megalodon/src/entities/activity.ts: -------------------------------------------------------------------------------- 1 | export type Activity = { 2 | week: string 3 | statuses: string 4 | logins: string 5 | registrations: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/entities/announcement.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | import { StatusTag } from './status.js' 3 | 4 | export type Announcement = { 5 | id: string 6 | content: string 7 | starts_at: string | null 8 | ends_at: string | null 9 | published: boolean 10 | all_day: boolean 11 | published_at: string 12 | updated_at: string | null 13 | read: boolean | null 14 | mentions: Array 15 | statuses: Array 16 | tags: Array 17 | emojis: Array 18 | reactions: Array 19 | } 20 | 21 | export type AnnouncementAccount = { 22 | id: string 23 | username: string 24 | url: string 25 | acct: string 26 | } 27 | 28 | export type AnnouncementStatus = { 29 | id: string 30 | url: string 31 | } 32 | 33 | export type AnnouncementReaction = { 34 | name: string 35 | count: number 36 | me: boolean | null 37 | url: string | null 38 | static_url: string | null 39 | } 40 | -------------------------------------------------------------------------------- /megalodon/src/entities/application.ts: -------------------------------------------------------------------------------- 1 | export type Application = { 2 | name: string 3 | website?: string | null 4 | vapid_key?: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/entities/async_attachment.ts: -------------------------------------------------------------------------------- 1 | import { Meta } from './attachment.js' 2 | 3 | export type AsyncAttachment = { 4 | id: string 5 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 6 | url: string | null 7 | remote_url: string | null 8 | preview_url: string 9 | text_url: string | null 10 | meta: Meta | null 11 | description: string | null 12 | blurhash: string | null 13 | } 14 | -------------------------------------------------------------------------------- /megalodon/src/entities/attachment.ts: -------------------------------------------------------------------------------- 1 | export type Sub = { 2 | // For Image, Gifv, and Video 3 | width?: number 4 | height?: number 5 | size?: string 6 | aspect?: number 7 | 8 | // For Gifv and Video 9 | frame_rate?: string 10 | 11 | // For Audio, Gifv, and Video 12 | duration?: number 13 | bitrate?: number 14 | } 15 | 16 | export type Focus = { 17 | x: number 18 | y: number 19 | } 20 | 21 | export type Meta = { 22 | original?: Sub 23 | small?: Sub 24 | focus?: Focus 25 | length?: string 26 | duration?: number 27 | fps?: number 28 | size?: string 29 | width?: number 30 | height?: number 31 | aspect?: number 32 | audio_encode?: string 33 | audio_bitrate?: string 34 | audio_channel?: string 35 | } 36 | 37 | export type Attachment = { 38 | id: string 39 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 40 | url: string 41 | remote_url: string | null 42 | preview_url: string | null 43 | text_url: string | null 44 | meta: Meta | null 45 | description: string | null 46 | blurhash: string | null 47 | } 48 | -------------------------------------------------------------------------------- /megalodon/src/entities/card.ts: -------------------------------------------------------------------------------- 1 | export type Card = { 2 | url: string 3 | title: string 4 | description: string 5 | type: 'link' | 'photo' | 'video' | 'rich' 6 | image: string | null 7 | author_name: string | null 8 | author_url: string | null 9 | provider_name: string | null 10 | provider_url: string | null 11 | html: string | null 12 | width: number | null 13 | height: number | null 14 | embed_url: string | null 15 | blurhash: string | null 16 | } 17 | -------------------------------------------------------------------------------- /megalodon/src/entities/context.ts: -------------------------------------------------------------------------------- 1 | import { Status } from './status.js' 2 | 3 | export type Context = { 4 | ancestors: Array 5 | descendants: Array 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/entities/conversation.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | 4 | export type Conversation = { 5 | id: string 6 | accounts: Array 7 | last_status: Status | null 8 | unread: boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/entities/emoji.ts: -------------------------------------------------------------------------------- 1 | export type Emoji = { 2 | shortcode: string 3 | static_url: string 4 | url: string 5 | visible_in_picker: boolean 6 | category?: string 7 | } 8 | -------------------------------------------------------------------------------- /megalodon/src/entities/featured_tag.ts: -------------------------------------------------------------------------------- 1 | export type FeaturedTag = { 2 | id: string 3 | name: string 4 | statuses_count: number 5 | last_status_at: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/entities/field.ts: -------------------------------------------------------------------------------- 1 | export type Field = { 2 | name: string 3 | value: string 4 | verified_at?: string | null 5 | verified?: boolean | false 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/entities/filter.ts: -------------------------------------------------------------------------------- 1 | export type Filter = { 2 | id: string 3 | phrase: string 4 | context: Array 5 | expires_at: string | null 6 | irreversible: boolean 7 | whole_word: boolean 8 | } 9 | 10 | export type FilterContext = string 11 | -------------------------------------------------------------------------------- /megalodon/src/entities/follow_request.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | import { Field } from './field.js' 3 | 4 | export type FollowRequest = { 5 | id: number 6 | username: string 7 | acct: string 8 | display_name: string 9 | locked: boolean 10 | bot: boolean 11 | discoverable?: boolean 12 | group: boolean 13 | created_at: string 14 | note: string 15 | url: string 16 | avatar: string 17 | avatar_static: string 18 | header: string 19 | header_static: string 20 | followers_count: number 21 | following_count: number 22 | statuses_count: number 23 | emojis: Array 24 | fields: Array 25 | } 26 | -------------------------------------------------------------------------------- /megalodon/src/entities/history.ts: -------------------------------------------------------------------------------- 1 | export type History = { 2 | day: string 3 | uses: number 4 | accounts: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/entities/identity_proof.ts: -------------------------------------------------------------------------------- 1 | export type IdentityProof = { 2 | provider: string 3 | provider_username: string 4 | updated_at: string 5 | proof_url: string 6 | profile_url: string 7 | } 8 | -------------------------------------------------------------------------------- /megalodon/src/entities/instance.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { URLs } from './urls.js' 3 | import { Stats } from './stats.js' 4 | 5 | export type Instance = { 6 | uri: string 7 | title: string 8 | description: string 9 | email: string 10 | version: string 11 | thumbnail: string | null 12 | urls: URLs | null 13 | stats: Stats 14 | languages: Array 15 | registrations: boolean 16 | approval_required: boolean 17 | invites_enabled?: boolean 18 | configuration: { 19 | statuses: { 20 | max_characters: number 21 | max_media_attachments?: number 22 | characters_reserved_per_url?: number 23 | } 24 | polls?: { 25 | max_options: number 26 | max_characters_per_option: number 27 | min_expiration: number 28 | max_expiration: number 29 | } 30 | } 31 | contact_account?: Account 32 | rules?: Array 33 | } 34 | 35 | export type InstanceRule = { 36 | id: string 37 | text: string 38 | } 39 | -------------------------------------------------------------------------------- /megalodon/src/entities/list.ts: -------------------------------------------------------------------------------- 1 | export type List = { 2 | id: string 3 | title: string 4 | replies_policy: RepliesPolicy | null 5 | } 6 | 7 | export type RepliesPolicy = 'followed' | 'list' | 'none' 8 | -------------------------------------------------------------------------------- /megalodon/src/entities/marker.ts: -------------------------------------------------------------------------------- 1 | export type Marker = { 2 | home?: { 3 | last_read_id: string 4 | version: number 5 | updated_at: string 6 | } 7 | notifications?: { 8 | last_read_id: string 9 | version: number 10 | updated_at: string 11 | unread_count?: number 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /megalodon/src/entities/mention.ts: -------------------------------------------------------------------------------- 1 | export type Mention = { 2 | id: string 3 | username: string 4 | url: string 5 | acct: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/entities/notification.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | import { Reaction } from './reaction.js' 4 | 5 | export type Notification = { 6 | account: Account | null 7 | created_at: string 8 | id: string 9 | status?: Status 10 | reaction?: Reaction 11 | type: NotificationType 12 | target?: Account 13 | } 14 | 15 | export type NotificationType = string 16 | -------------------------------------------------------------------------------- /megalodon/src/entities/poll.ts: -------------------------------------------------------------------------------- 1 | export type Poll = { 2 | id: string 3 | expires_at: string | null 4 | expired: boolean 5 | multiple: boolean 6 | votes_count: number 7 | options: Array 8 | voted: boolean 9 | } 10 | 11 | export type PollOption = { 12 | title: string 13 | votes_count: number | null 14 | } 15 | -------------------------------------------------------------------------------- /megalodon/src/entities/preferences.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type Preferences = { 4 | 'posting:default:visibility': StatusVisibility 5 | 'posting:default:sensitive': boolean 6 | 'posting:default:language': string | null 7 | 'reading:expand:media': 'default' | 'show_all' | 'hide_all' 8 | 'reading:expand:spoilers': boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/entities/push_subscription.ts: -------------------------------------------------------------------------------- 1 | export type Alerts = { 2 | follow: boolean 3 | favourite: boolean 4 | mention: boolean 5 | reblog: boolean 6 | poll: boolean 7 | } 8 | 9 | export type PushSubscription = { 10 | id: string 11 | endpoint: string 12 | server_key: string 13 | alerts: Alerts 14 | } 15 | -------------------------------------------------------------------------------- /megalodon/src/entities/reaction.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | 3 | export type Reaction = { 4 | count: number 5 | me: boolean 6 | name: string 7 | url?: string 8 | static_url?: string 9 | accounts?: Array 10 | account_ids?: Array 11 | } 12 | -------------------------------------------------------------------------------- /megalodon/src/entities/relationship.ts: -------------------------------------------------------------------------------- 1 | export type Relationship = { 2 | id: string 3 | following: boolean 4 | followed_by: boolean 5 | blocking: boolean 6 | blocked_by: boolean 7 | muting: boolean 8 | muting_notifications: boolean 9 | requested: boolean 10 | domain_blocking: boolean 11 | showing_reblogs: boolean 12 | endorsed: boolean 13 | notifying: boolean 14 | note: string | null 15 | } 16 | -------------------------------------------------------------------------------- /megalodon/src/entities/report.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | 3 | export type Report = { 4 | id: string 5 | action_taken: boolean 6 | action_taken_at: string | null 7 | status_ids: Array | null 8 | rule_ids: Array | null 9 | // These parameters don't exist in Pleroma 10 | category: Category | null 11 | comment: string | null 12 | forwarded: boolean | null 13 | target_account?: Account | null 14 | } 15 | 16 | export type Category = 'spam' | 'violation' | 'other' 17 | -------------------------------------------------------------------------------- /megalodon/src/entities/results.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | import { Tag } from './tag.js' 4 | 5 | export type Results = { 6 | accounts: Array 7 | statuses: Array 8 | hashtags: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/entities/role.ts: -------------------------------------------------------------------------------- 1 | export type Role = { 2 | name: string 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/src/entities/scheduled_status.ts: -------------------------------------------------------------------------------- 1 | import { StatusParams } from './status_params.js' 2 | import { Attachment } from './attachment.js' 3 | 4 | export type ScheduledStatus = { 5 | id: string 6 | scheduled_at: string 7 | params: StatusParams 8 | media_attachments: Array | null 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/entities/source.ts: -------------------------------------------------------------------------------- 1 | import { Field } from './field.js' 2 | 3 | export type Source = { 4 | privacy: string | null 5 | sensitive: boolean | null 6 | language: string | null 7 | note: string 8 | fields: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/entities/stats.ts: -------------------------------------------------------------------------------- 1 | export type Stats = { 2 | user_count: number 3 | status_count: number 4 | domain_count: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/entities/status.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Application } from './application.js' 3 | import { Emoji } from './emoji.js' 4 | import { Attachment } from './attachment.js' 5 | import { Mention } from './mention.js' 6 | import { Reaction } from './reaction.js' 7 | import { Card } from './card.js' 8 | import { Poll } from './poll.js' 9 | 10 | export type Status = { 11 | id: string 12 | uri: string 13 | url?: string 14 | account: Account 15 | in_reply_to_id: string | null 16 | in_reply_to_account_id: string | null 17 | reblog: Status | null 18 | content: string 19 | plain_content: string | null 20 | created_at: string 21 | edited_at: string | null 22 | emojis: Emoji[] 23 | replies_count: number 24 | reblogs_count: number 25 | favourites_count: number 26 | reblogged: boolean | null 27 | favourited: boolean | null 28 | muted: boolean | null 29 | sensitive: boolean 30 | spoiler_text: string 31 | visibility: StatusVisibility 32 | media_attachments: Array 33 | mentions: Array 34 | tags: Array 35 | card: Card | null 36 | poll: Poll | null 37 | application: Application | null 38 | language: string | null 39 | pinned: boolean | null 40 | emoji_reactions: Array 41 | quote: boolean 42 | bookmarked: boolean 43 | } 44 | 45 | export type StatusTag = { 46 | name: string 47 | url: string 48 | } 49 | 50 | export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct' 51 | -------------------------------------------------------------------------------- /megalodon/src/entities/status_params.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type StatusParams = { 4 | text: string 5 | in_reply_to_id: string | null 6 | media_ids: Array | null 7 | sensitive: boolean | null 8 | spoiler_text: string | null 9 | visibility: StatusVisibility | null 10 | scheduled_at: string | null 11 | application_id: number | null 12 | } 13 | -------------------------------------------------------------------------------- /megalodon/src/entities/status_source.ts: -------------------------------------------------------------------------------- 1 | export type StatusSource = { 2 | id: string 3 | text: string 4 | spoiler_text: string 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/entities/tag.ts: -------------------------------------------------------------------------------- 1 | import { History } from './history.js' 2 | 3 | export type Tag = { 4 | name: string 5 | url: string 6 | history: Array 7 | following?: boolean 8 | } 9 | -------------------------------------------------------------------------------- /megalodon/src/entities/token.ts: -------------------------------------------------------------------------------- 1 | export type Token = { 2 | access_token: string 3 | token_type: string 4 | scope: string 5 | created_at: number 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/entities/urls.ts: -------------------------------------------------------------------------------- 1 | export type URLs = { 2 | streaming_api: string 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/src/filter_context.ts: -------------------------------------------------------------------------------- 1 | import Entity from './entity.js' 2 | 3 | namespace FilterContext { 4 | export const Home: Entity.FilterContext = 'home' 5 | export const Notifications: Entity.FilterContext = 'notifications' 6 | export const Public: Entity.FilterContext = 'public' 7 | export const Thread: Entity.FilterContext = 'thread' 8 | export const Account: Entity.FilterContext = 'account' 9 | } 10 | 11 | export default FilterContext 12 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/announcement.ts: -------------------------------------------------------------------------------- 1 | export type Announcement = { 2 | id: string 3 | createdAt: string 4 | updatedAt: string | null 5 | text: string 6 | title: string 7 | imageurl: string | null 8 | isRead?: boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/app.ts: -------------------------------------------------------------------------------- 1 | export type App = { 2 | id: string 3 | name: string 4 | callbackUrl: string | null 5 | permission: Array 6 | secret?: string 7 | isAuthorized?: boolean 8 | } 9 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/blocking.ts: -------------------------------------------------------------------------------- 1 | import { UserDetail } from './userDetail.js' 2 | 3 | export type Blocking = { 4 | id: string 5 | createdAt: string 6 | blockeeId: string 7 | blockee: UserDetail 8 | } 9 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/createdNote.ts: -------------------------------------------------------------------------------- 1 | import { Note } from './note.js' 2 | 3 | export type CreatedNote = { 4 | createdNote: Note 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/emoji.ts: -------------------------------------------------------------------------------- 1 | export type Emoji = { 2 | name: string 3 | url: string 4 | category: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/favorite.ts: -------------------------------------------------------------------------------- 1 | import { Note } from './note.js' 2 | 3 | export type Favorite = { 4 | id: string 5 | createdAt: string 6 | noteId: string 7 | note: Note 8 | } 9 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/field.ts: -------------------------------------------------------------------------------- 1 | export type Field = { 2 | name: string 3 | value: string 4 | verified?: boolean 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/file.ts: -------------------------------------------------------------------------------- 1 | export type File = { 2 | id: string 3 | createdAt: string 4 | name: string 5 | type: string 6 | md5: string 7 | size: number 8 | isSensitive: boolean 9 | blurhash: string | null 10 | properties: { 11 | width?: number 12 | height?: number 13 | avgColor?: string 14 | } 15 | url: string | null 16 | thumbnailUrl: string | null 17 | comment: string | null 18 | } 19 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/follow.ts: -------------------------------------------------------------------------------- 1 | import { UserDetail } from './userDetail.js' 2 | 3 | export type Follow = { 4 | id: string 5 | createdAt: string 6 | followeeId: string 7 | followerId: string 8 | follower: UserDetail 9 | followee: UserDetail 10 | } 11 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/followRequest.ts: -------------------------------------------------------------------------------- 1 | import { User } from './user.js' 2 | 3 | export type FollowRequest = { 4 | id: string 5 | follower: User 6 | followee: User 7 | } 8 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/hashtag.ts: -------------------------------------------------------------------------------- 1 | export type Hashtag = { 2 | tag: string 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/instance.ts: -------------------------------------------------------------------------------- 1 | import { Field } from './field.js' 2 | 3 | export type URLs = { 4 | streaming_api: string 5 | } 6 | 7 | export type AccountEmoji = { 8 | shortcode: string 9 | static_url: string 10 | url: string 11 | visible_in_picker: boolean 12 | } 13 | 14 | export type Instance = { 15 | uri: string 16 | title: string 17 | short_description: string 18 | description: string 19 | email: string 20 | version: string 21 | urls: URLs 22 | stats: { 23 | user_count: number 24 | status_count: number 25 | domain_count: number 26 | } 27 | thumbnail: string | null 28 | languages: Array 29 | registrations: boolean 30 | approval_required: boolean 31 | invites_enabled: boolean 32 | configuration: { 33 | statuses: { 34 | max_characters: number 35 | max_media_attachments: number 36 | characters_reserved_per_url: number 37 | } 38 | media_attachments: { 39 | supported_mime_types: Array 40 | image_size_limit: number 41 | image_matrix_limit: number 42 | video_size_limit: number 43 | video_frame_rate_limit: number 44 | video_matrix_limit: number 45 | } 46 | polls: { 47 | max_options: number 48 | max_characters_per_option: number 49 | min_expiration: number 50 | max_expiration: number 51 | } 52 | } 53 | contact_account: { 54 | id: string 55 | username: string 56 | acct: string 57 | display_name: string 58 | locked: boolean 59 | created_at: string 60 | followers_count: number 61 | following_count: number 62 | statuses_count: number 63 | note: string 64 | url: string 65 | avatar: string 66 | avatar_static: string 67 | header: string 68 | header_static: string 69 | emojis: Array 70 | fields: Array 71 | bot: boolean 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/list.ts: -------------------------------------------------------------------------------- 1 | export type List = { 2 | id: string 3 | createdAt: string 4 | name: string 5 | userIds?: Array 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/meta.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | 3 | export type Meta = { 4 | maintainerName: string | null 5 | maintainerEmail: string | null 6 | name: string 7 | version: string 8 | uri: string 9 | description: string | null 10 | langs: Array 11 | disableRegistration: boolean 12 | disableLocalTimeline: boolean 13 | bannerUrl: string 14 | maxNoteTextLength: number 15 | emojis: Array 16 | features: { 17 | registration: boolean 18 | emailRequiredForSignup: boolean 19 | elasticsearch: boolean 20 | hcaptcha: boolean 21 | recaptcha: boolean 22 | turnstile: boolean 23 | objectStorage: boolean 24 | serviceWorker: boolean 25 | miauth: boolean 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/mute.ts: -------------------------------------------------------------------------------- 1 | import { UserDetail } from './userDetail.js' 2 | 3 | export type Mute = { 4 | id: string 5 | createdAt: string 6 | muteeId: string 7 | mutee: UserDetail 8 | } 9 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/note.ts: -------------------------------------------------------------------------------- 1 | import { User } from './user.js' 2 | import { Emoji } from './emoji.js' 3 | import { File } from './file.js' 4 | import { Poll } from './poll.js' 5 | 6 | export type Note = { 7 | id: string 8 | createdAt: string 9 | userId: string 10 | user: User 11 | text: string | null 12 | cw?: string | null 13 | visibility: NoteVisibility 14 | renoteCount: number 15 | repliesCount: number 16 | reactions: { [key: string]: number } 17 | emojis?: Array | null 18 | fileIds?: Array 19 | files?: Array 20 | replyId?: string | null 21 | renoteId?: string | null 22 | uri?: string 23 | reply?: Note 24 | renote?: Note 25 | tags?: Array 26 | poll?: Poll | null 27 | mentions?: Array 28 | myReaction?: string | null 29 | } 30 | 31 | export type NoteVisibility = 'public' | 'home' | 'followers' | 'specified' | 'hidden' 32 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/notification.ts: -------------------------------------------------------------------------------- 1 | import { User } from './user.js' 2 | import { Note } from './note.js' 3 | 4 | export type Notification = { 5 | id: string 6 | createdAt: string 7 | type: NotificationType 8 | userId?: string | null 9 | user?: User 10 | note?: Note 11 | reaction?: string | null 12 | } 13 | 14 | export type NotificationType = string 15 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/poll.ts: -------------------------------------------------------------------------------- 1 | export type Choice = { 2 | text: string 3 | votes: number 4 | isVoted?: boolean 5 | } 6 | 7 | export type Poll = { 8 | multiple: boolean 9 | expiresAt: string 10 | choices: Array 11 | } 12 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/reaction.ts: -------------------------------------------------------------------------------- 1 | import { User } from './user.js' 2 | 3 | export type Reaction = { 4 | id: string 5 | createdAt: string 6 | user: User 7 | type: string 8 | } 9 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/relation.ts: -------------------------------------------------------------------------------- 1 | export type Relation = { 2 | id: string 3 | isFollowing: boolean 4 | hasPendingFollowRequestFromYou: boolean 5 | hasPendingFollowRequestToYou: boolean 6 | isFollowed: boolean 7 | isBlocking: boolean 8 | isBlocked: boolean 9 | isMuted: boolean 10 | isRenoteMuted: boolean 11 | } 12 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/session.ts: -------------------------------------------------------------------------------- 1 | export type Session = { 2 | token: string 3 | url: string 4 | } 5 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/stats.ts: -------------------------------------------------------------------------------- 1 | export type Stats = { 2 | notesCount: number 3 | originalNotesCount: number 4 | usersCount: number 5 | originalUsersCount: number 6 | instances: number 7 | } 8 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/user.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | 3 | export type User = { 4 | id: string 5 | name: string | null 6 | username: string 7 | host: string | null 8 | avatarUrl: string | null 9 | avatarBlurhash: string | null 10 | avatarColor: string | null 11 | isAdmin?: boolean 12 | isModerator?: boolean 13 | isBot?: boolean 14 | isCat?: boolean 15 | isIndexable?: boolean 16 | speakAsCat?: boolean 17 | emojis: Array 18 | } 19 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entities/userDetail.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | import { Note } from './note.js' 3 | import { Field } from './field.js' 4 | 5 | export type UserDetail = { 6 | id: string 7 | name: string | null 8 | username: string 9 | host: string | null 10 | avatarUrl: string | null 11 | avatarBlurhash: string | null 12 | avatarColor: string | null 13 | isAdmin?: boolean 14 | isModerator?: boolean 15 | isBot?: boolean 16 | isCat?: boolean 17 | isIndexable?: boolean 18 | speakAsCat?: boolean 19 | emojis: Array 20 | url: string | null 21 | uri: string | null 22 | movedToUri: string | null 23 | createdAt: string 24 | updatedAt: string | null 25 | bannerUrl: string | null 26 | bannerBlurhash: string | null 27 | bannerColor: string | null 28 | isLocked: boolean 29 | isSilenced: boolean 30 | isSuspended: boolean 31 | description: string | null 32 | lang: string | null 33 | fields: Array 34 | followersCount: number 35 | followingCount: number 36 | notesCount: number 37 | pinnedNoteIds: Array 38 | pinnedNotes: Array 39 | isFollowing?: boolean 40 | isFollowed?: boolean 41 | hasPendingFollowRequestFromYou?: boolean 42 | hasPendintFollowRequestToYou?: boolean 43 | isBlocking?: boolean 44 | isBlocked?: boolean 45 | isMuted?: boolean 46 | isRenoteMuted?: boolean 47 | } 48 | 49 | export type UserDetailMe = UserDetail & { 50 | alwaysMarkNsfw: boolean 51 | } 52 | -------------------------------------------------------------------------------- /megalodon/src/firefish/entity.ts: -------------------------------------------------------------------------------- 1 | import * as announcement from './entities/announcement.js' 2 | import * as app from './entities/app.js' 3 | import * as blocking from './entities/blocking.js' 4 | import * as created_note from './entities/createdNote.js' 5 | import * as emoji from './entities/emoji.js' 6 | import * as favorite from './entities/favorite.js' 7 | import * as field from './entities/field.js' 8 | import * as file from './entities/file.js' 9 | import * as follow from './entities/follow.js' 10 | import * as follow_request from './entities/followRequest.js' 11 | import * as hashtag from './entities/hashtag.js' 12 | import * as instance from './entities/instance.js' 13 | import * as list from './entities/list.js' 14 | import * as meta from './entities/meta.js' 15 | import * as mute from './entities/mute.js' 16 | import * as note from './entities/note.js' 17 | import * as notification from './entities/notification.js' 18 | import * as poll from './entities/poll.js' 19 | import * as reaction from './entities/reaction.js' 20 | import * as relation from './entities/relation.js' 21 | import * as session from './entities/session.js' 22 | import * as stats from './entities/stats.js' 23 | import * as user from './entities/user.js' 24 | import * as user_detail from './entities/userDetail.js' 25 | 26 | export namespace Entity { 27 | export type Announcement = announcement.Announcement 28 | export type App = app.App 29 | export type Blocking = blocking.Blocking 30 | export type CreatedNote = created_note.CreatedNote 31 | export type Emoji = emoji.Emoji 32 | export type Favorite = favorite.Favorite 33 | export type Field = field.Field 34 | export type File = file.File 35 | export type Follow = follow.Follow 36 | export type FollowRequest = follow_request.FollowRequest 37 | export type Hashtag = hashtag.Hashtag 38 | export type Instance = instance.Instance 39 | export type AccountEmoji = instance.AccountEmoji 40 | export type List = list.List 41 | export type Meta = meta.Meta 42 | export type Mute = mute.Mute 43 | export type Note = note.Note 44 | export type NoteVisibility = note.NoteVisibility 45 | export type Notification = notification.Notification 46 | export type NotificationType = notification.NotificationType 47 | export type Poll = poll.Poll 48 | export type Choice = poll.Choice 49 | export type Reaction = reaction.Reaction 50 | export type Relation = relation.Relation 51 | export type Session = session.Session 52 | export type Stats = stats.Stats 53 | export type User = user.User 54 | export type UserDetail = user_detail.UserDetail 55 | export type UserDetailMe = user_detail.UserDetailMe 56 | } 57 | 58 | export default Entity 59 | -------------------------------------------------------------------------------- /megalodon/src/firefish/notification.ts: -------------------------------------------------------------------------------- 1 | import FirefishEntity from './entity.js' 2 | 3 | namespace FirefishNotificationType { 4 | export const Follow: FirefishEntity.NotificationType = 'follow' 5 | export const Mention: FirefishEntity.NotificationType = 'mention' 6 | export const Reply: FirefishEntity.NotificationType = 'reply' 7 | export const Renote: FirefishEntity.NotificationType = 'renote' 8 | export const Quote: FirefishEntity.NotificationType = 'quote' 9 | export const Reaction: FirefishEntity.NotificationType = 'reaction' 10 | export const PollVote: FirefishEntity.NotificationType = 'pollVote' 11 | export const PollEnded: FirefishEntity.NotificationType = 'pollEnded' 12 | export const ReceiveFollowRequest: FirefishEntity.NotificationType = 'receiveFollowRequest' 13 | export const FollowRequestAccepted: FirefishEntity.NotificationType = 'followRequestAccepted' 14 | export const GroupInvited: FirefishEntity.NotificationType = 'groupInvited' 15 | export const App: FirefishEntity.NotificationType = 'app' 16 | } 17 | 18 | export default FirefishNotificationType 19 | -------------------------------------------------------------------------------- /megalodon/src/firefish/oauth.ts: -------------------------------------------------------------------------------- 1 | import OAuth from '@/oauth.js' 2 | 3 | export type AppDataFromServer = { 4 | id: string 5 | name: string 6 | callbackUrl: string | null 7 | permission: Array 8 | secret?: string 9 | isAuthorized?: boolean 10 | } 11 | 12 | export type TokenDataFromServer = { 13 | accessToken: string 14 | } 15 | 16 | export function toAppData(appData: AppDataFromServer): OAuth.AppData { 17 | return { 18 | id: appData.id, 19 | name: appData.name, 20 | website: null, 21 | redirect_uri: appData.callbackUrl, 22 | client_id: '', 23 | client_secret: appData.secret ?? '', 24 | url: null, 25 | session_token: null 26 | } 27 | } 28 | 29 | export function toTokenData(tokenData: TokenDataFromServer): OAuth.TokenData { 30 | return { 31 | access_token: tokenData.accessToken, 32 | token_type: 'Firefish', 33 | scope: null, 34 | created_at: null, 35 | expires_in: null, 36 | refresh_token: null 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/account.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | import { Field } from './field.js' 3 | import { Source } from './source.js' 4 | 5 | export type Account = { 6 | id: string 7 | username: string 8 | acct: string 9 | display_name: string 10 | locked: boolean 11 | discoverable?: boolean 12 | group: boolean | null 13 | created_at: string 14 | followers_count: number 15 | following_count: number 16 | statuses_count: number 17 | note: string 18 | url: string 19 | avatar: string 20 | avatar_static: string 21 | header: string 22 | header_static: string 23 | emojis: Array 24 | moved: Account | null 25 | fields: Array 26 | bot: boolean 27 | source?: Source 28 | } 29 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/activity.ts: -------------------------------------------------------------------------------- 1 | export type Activity = { 2 | week: string 3 | statuses: string 4 | logins: string 5 | registrations: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/application.ts: -------------------------------------------------------------------------------- 1 | export type Application = { 2 | name: string 3 | website?: string | null 4 | vapid_key?: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/async_attachment.ts: -------------------------------------------------------------------------------- 1 | import { Meta } from './attachment.js' 2 | 3 | export type AsyncAttachment = { 4 | id: string 5 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 6 | url: string | null 7 | remote_url: string | null 8 | preview_url: string 9 | text_url: string | null 10 | meta: Meta | null 11 | description: string | null 12 | blurhash: string | null 13 | } 14 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/attachment.ts: -------------------------------------------------------------------------------- 1 | export type Sub = { 2 | // For Image, Gifv, and Video 3 | width?: number 4 | height?: number 5 | size?: string 6 | aspect?: number 7 | 8 | // For Gifv and Video 9 | frame_rate?: string 10 | 11 | // For Audio, Gifv, and Video 12 | duration?: number 13 | bitrate?: number 14 | } 15 | 16 | export type Focus = { 17 | x: number 18 | y: number 19 | } 20 | 21 | export type Meta = { 22 | original?: Sub 23 | small?: Sub 24 | focus?: Focus 25 | length?: string 26 | duration?: number 27 | fps?: number 28 | size?: string 29 | width?: number 30 | height?: number 31 | aspect?: number 32 | audio_encode?: string 33 | audio_bitrate?: string 34 | audio_channel?: string 35 | } 36 | 37 | export type Attachment = { 38 | id: string 39 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 40 | url: string 41 | remote_url: string | null 42 | preview_url: string | null 43 | text_url: string | null 44 | meta: Meta | null 45 | description: string | null 46 | blurhash: string | null 47 | } 48 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/card.ts: -------------------------------------------------------------------------------- 1 | export type Card = { 2 | url: string 3 | title: string 4 | description: string 5 | type: 'link' | 'photo' | 'video' | 'rich' 6 | image: string | null 7 | author_name: string 8 | author_url: string 9 | provider_name: string 10 | provider_url: string 11 | html: string 12 | width: number 13 | height: number 14 | blurhash: string | null 15 | } 16 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/context.ts: -------------------------------------------------------------------------------- 1 | import { Status } from './status.js' 2 | 3 | export type Context = { 4 | ancestors: Array 5 | descendants: Array 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/conversation.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | 4 | export type Conversation = { 5 | id: string 6 | accounts: Array 7 | last_status: Status | null 8 | unread: boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/emoji.ts: -------------------------------------------------------------------------------- 1 | export type Emoji = { 2 | shortcode: string 3 | static_url: string 4 | url: string 5 | visible_in_picker: boolean 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/featured_tag.ts: -------------------------------------------------------------------------------- 1 | export type FeaturedTag = { 2 | id: string 3 | name: string 4 | statuses_count: number 5 | last_status_at: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/field.ts: -------------------------------------------------------------------------------- 1 | export type Field = { 2 | name: string 3 | value: string 4 | verified_at: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/filter.ts: -------------------------------------------------------------------------------- 1 | export type Filter = { 2 | id: string 3 | phrase: string 4 | context: Array 5 | expires_at: string | null 6 | irreversible: boolean 7 | whole_word: boolean 8 | } 9 | 10 | export type FilterContext = string 11 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/follow_request.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | import { Field } from './field.js' 3 | 4 | export type FollowRequest = { 5 | id: number 6 | username: string 7 | acct: string 8 | display_name: string 9 | locked: boolean 10 | bot: boolean 11 | discoverable?: boolean 12 | group: boolean 13 | created_at: string 14 | note: string 15 | url: string 16 | avatar: string 17 | avatar_static: string 18 | header: string 19 | header_static: string 20 | followers_count: number 21 | following_count: number 22 | statuses_count: number 23 | emojis: Array 24 | fields: Array 25 | } 26 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/history.ts: -------------------------------------------------------------------------------- 1 | export type History = { 2 | day: string 3 | uses: number 4 | accounts: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/identity_proof.ts: -------------------------------------------------------------------------------- 1 | export type IdentityProof = { 2 | provider: string 3 | provider_username: string 4 | updated_at: string 5 | proof_url: string 6 | profile_url: string 7 | } 8 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/instance.ts: -------------------------------------------------------------------------------- 1 | import { URLs } from './urls.js' 2 | import { Stats } from './stats.js' 3 | import { Account } from './account.js' 4 | 5 | export type Instance = { 6 | uri: string 7 | title: string 8 | description: string 9 | email: string 10 | version: string 11 | thumbnail: string | null 12 | urls: URLs | null 13 | stats: Stats 14 | languages: Array 15 | registrations: boolean 16 | approval_required: boolean 17 | invites_enabled: boolean 18 | max_toot_chars: number 19 | contact_account: Account 20 | rules: Array 21 | } 22 | 23 | export type InstanceRule = { 24 | id: string 25 | text: string 26 | } 27 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/list.ts: -------------------------------------------------------------------------------- 1 | export type List = { 2 | id: string 3 | title: string 4 | replies_policy: RepliesPolicy 5 | } 6 | 7 | export type RepliesPolicy = 'followed' | 'list' | 'none' 8 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/marker.ts: -------------------------------------------------------------------------------- 1 | export type Marker = { 2 | home: { 3 | last_read_id: string 4 | version: number 5 | updated_at: string 6 | } 7 | notifications: { 8 | last_read_id: string 9 | version: number 10 | updated_at: string 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/mention.ts: -------------------------------------------------------------------------------- 1 | export type Mention = { 2 | id: string 3 | username: string 4 | url: string 5 | acct: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/notification.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | 4 | export type Notification = { 5 | account: Account 6 | created_at: string 7 | id: string 8 | status?: Status 9 | type: NotificationType 10 | } 11 | 12 | export type NotificationType = string 13 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/poll.ts: -------------------------------------------------------------------------------- 1 | export type Poll = { 2 | id: string 3 | expires_at: string | null 4 | expired: boolean 5 | multiple: boolean 6 | votes_count: number 7 | options: Array 8 | voted: boolean 9 | } 10 | 11 | export type PollOption = { 12 | title: string 13 | votes_count: number | null 14 | } 15 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/preferences.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type Preferences = { 4 | 'posting:default:visibility': StatusVisibility 5 | 'posting:default:sensitive': boolean 6 | 'posting:default:language': string | null 7 | 'reading:expand:media': 'default' | 'show_all' | 'hide_all' 8 | 'reading:expand:spoilers': boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/push_subscription.ts: -------------------------------------------------------------------------------- 1 | export type Alerts = { 2 | follow: boolean 3 | favourite: boolean 4 | mention: boolean 5 | reblog: boolean 6 | poll: boolean 7 | } 8 | 9 | export type PushSubscription = { 10 | id: string 11 | endpoint: string 12 | server_key: string 13 | alerts: Alerts 14 | } 15 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/relationship.ts: -------------------------------------------------------------------------------- 1 | export type Relationship = { 2 | id: string 3 | following: boolean 4 | followed_by: boolean 5 | blocking: boolean 6 | blocked_by: boolean 7 | muting: boolean 8 | muting_notifications: boolean 9 | requested: boolean 10 | domain_blocking: boolean 11 | showing_reblogs: boolean 12 | endorsed: boolean 13 | notifying: boolean 14 | note: string | null 15 | } 16 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/report.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | 3 | export type Report = { 4 | id: string 5 | action_taken: boolean 6 | category: Category 7 | comment: string 8 | forwarded: boolean 9 | status_ids: Array | null 10 | rule_ids: Array | null 11 | target_account: Account 12 | } 13 | 14 | export type Category = 'spam' | 'violation' | 'other' 15 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/results.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | import { Tag } from './tag.js' 4 | 5 | export type Results = { 6 | accounts: Array 7 | statuses: Array 8 | hashtags: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/scheduled_status.ts: -------------------------------------------------------------------------------- 1 | import { Attachment } from './attachment.js' 2 | import { StatusParams } from './status_params.js' 3 | 4 | export type ScheduledStatus = { 5 | id: string 6 | scheduled_at: string 7 | params: StatusParams 8 | media_attachments: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/source.ts: -------------------------------------------------------------------------------- 1 | import { Field } from './field.js' 2 | 3 | export type Source = { 4 | privacy: string | null 5 | sensitive: boolean | null 6 | language: string | null 7 | note: string 8 | fields: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/stats.ts: -------------------------------------------------------------------------------- 1 | export type Stats = { 2 | user_count: number 3 | status_count: number 4 | domain_count: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/status.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Emoji } from './emoji.js' 3 | import { Attachment } from './attachment.js' 4 | import { Application } from './application.js' 5 | import { Mention } from './mention.js' 6 | import { Card } from './card.js' 7 | import { Poll } from './poll.js' 8 | 9 | export type Status = { 10 | id: string 11 | uri: string 12 | url: string 13 | account: Account 14 | in_reply_to_id: string | null 15 | in_reply_to_account_id: string | null 16 | reblog: Status | null 17 | content: string 18 | created_at: string 19 | emojis: Emoji[] 20 | replies_count: number 21 | reblogs_count: number 22 | favourites_count: number 23 | reblogged: boolean | null 24 | favourited: boolean | null 25 | muted: boolean | null 26 | sensitive: boolean 27 | spoiler_text: string 28 | visibility: StatusVisibility 29 | media_attachments: Array 30 | mentions: Array 31 | tags: Array 32 | card: Card | null 33 | poll: Poll | null 34 | application: Application | null 35 | language: string | null 36 | pinned: boolean | null 37 | bookmarked?: boolean 38 | // These parameters are unique parameters in fedibird.com for quote. 39 | quote_id?: string 40 | quote?: Status | null 41 | } 42 | 43 | export type StatusTag = { 44 | name: string 45 | url: string 46 | } 47 | 48 | export type StatusVisibility = 'public' | 'unlisted' | 'private' 49 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/status_params.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type StatusParams = { 4 | text: string 5 | in_reply_to_id: string | null 6 | media_ids: Array | null 7 | sensitive: boolean | null 8 | spoiler_text: string | null 9 | visibility: StatusVisibility | null 10 | scheduled_at: string | null 11 | application_id: string 12 | } 13 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/status_source.ts: -------------------------------------------------------------------------------- 1 | export type StatusSource = { 2 | id: string 3 | text: string 4 | spoiler_text: string 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/tag.ts: -------------------------------------------------------------------------------- 1 | import { History } from './history.js' 2 | 3 | export type Tag = { 4 | name: string 5 | url: string 6 | history: Array 7 | following?: boolean 8 | } 9 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/token.ts: -------------------------------------------------------------------------------- 1 | export type Token = { 2 | access_token: string 3 | token_type: string 4 | scope: string 5 | created_at: number 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/friendica/entities/urls.ts: -------------------------------------------------------------------------------- 1 | export type URLs = { 2 | streaming_api: string 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/src/friendica/notification.ts: -------------------------------------------------------------------------------- 1 | import FriendicaEntity from './entity.js' 2 | 3 | namespace FriendicaNotificationType { 4 | export const Mention: FriendicaEntity.NotificationType = 'mention' 5 | export const Reblog: FriendicaEntity.NotificationType = 'reblog' 6 | export const Favourite: FriendicaEntity.NotificationType = 'favourite' 7 | export const Follow: FriendicaEntity.NotificationType = 'follow' 8 | export const Poll: FriendicaEntity.NotificationType = 'poll' 9 | export const FollowRequest: FriendicaEntity.NotificationType = 'follow_request' 10 | export const Status: FriendicaEntity.NotificationType = 'status' 11 | export const Update: FriendicaEntity.NotificationType = 'update' 12 | } 13 | 14 | export default FriendicaNotificationType 15 | -------------------------------------------------------------------------------- /megalodon/src/friendica/oauth.ts: -------------------------------------------------------------------------------- 1 | import OAuth from '@/oauth.js' 2 | 3 | export type AppDataFromServer = { 4 | id: string 5 | name: string 6 | website: string | null 7 | redirect_uri: string 8 | client_id: string 9 | client_secret: string 10 | } 11 | 12 | export type TokenDataFromServer = { 13 | access_token: string 14 | token_type: string 15 | scope: string 16 | created_at: number 17 | } 18 | 19 | export function toAppData(appData: AppDataFromServer): OAuth.AppData { 20 | return { 21 | id: appData.id, 22 | name: appData.name, 23 | website: appData.website, 24 | redirect_uri: appData.redirect_uri, 25 | client_id: appData.client_id, 26 | client_secret: appData.client_secret, 27 | url: null, 28 | session_token: null 29 | } 30 | } 31 | 32 | export function toTokenData(tokenData: TokenDataFromServer): OAuth.TokenData { 33 | return { 34 | access_token: tokenData.access_token, 35 | token_type: tokenData.token_type, 36 | scope: tokenData.scope, 37 | created_at: tokenData.created_at, 38 | expires_in: null, 39 | refresh_token: null 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /megalodon/src/friendica/web_socket.ts: -------------------------------------------------------------------------------- 1 | import { WebSocketInterface } from '../megalodon.js' 2 | import { EventEmitter } from 'events' 3 | 4 | export default class WebSocket extends EventEmitter implements WebSocketInterface { 5 | constructor(_url: string, _stream: string, _params: string | undefined, _accessToken: string, _userAgent: string) { 6 | super() 7 | } 8 | public start() {} 9 | public stop() {} 10 | } 11 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/account.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | import { Field } from './field.js' 3 | import { Source } from './source.js' 4 | import { Role } from './role.js' 5 | 6 | export type Account = { 7 | id: string 8 | username: string 9 | acct: string 10 | display_name: string 11 | locked: boolean 12 | discoverable?: boolean 13 | suspended: boolean | null 14 | created_at: string 15 | followers_count: number 16 | following_count: number 17 | statuses_count: number 18 | note: string 19 | url: string 20 | avatar: string 21 | avatar_static: string 22 | header: string 23 | header_static: string 24 | emojis: Array 25 | moved: Account | null 26 | fields: Array 27 | bot: boolean 28 | source?: Source 29 | enable_rss?: boolean 30 | role?: Role 31 | mute_expires_at?: string 32 | } 33 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/application.ts: -------------------------------------------------------------------------------- 1 | export type Application = { 2 | name: string 3 | website?: string | null 4 | vapid_key?: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/attachment.ts: -------------------------------------------------------------------------------- 1 | export type Sub = { 2 | // For Image, Gifv, and Video 3 | width?: number 4 | height?: number 5 | size?: string 6 | aspect?: number 7 | 8 | // For Gifv and Video 9 | frame_rate?: string 10 | 11 | // For Audio, Gifv, and Video 12 | duration?: number 13 | bitrate?: number 14 | } 15 | 16 | export type Focus = { 17 | x: number 18 | y: number 19 | } 20 | 21 | export type Meta = { 22 | original?: Sub 23 | small?: Sub 24 | focus?: Focus 25 | length?: string 26 | duration?: number 27 | fps?: number 28 | size?: string 29 | width?: number 30 | height?: number 31 | aspect?: number 32 | audio_encode?: string 33 | audio_bitrate?: string 34 | audio_channel?: string 35 | } 36 | 37 | export type Attachment = { 38 | id: string 39 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 40 | url: string | null 41 | remote_url: string | null 42 | preview_url: string | null 43 | text_url: string | null 44 | meta: Meta | null 45 | description: string | null 46 | blurhash: string | null 47 | } 48 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/card.ts: -------------------------------------------------------------------------------- 1 | export type Card = { 2 | url: string 3 | title: string 4 | description: string 5 | type: 'link' | 'photo' | 'video' | 'rich' 6 | image: string | null 7 | author_name: string | null 8 | author_url: string | null 9 | provider_name: string | null 10 | provider_url: string | null 11 | html: string | null 12 | width: number | null 13 | height: number | null 14 | } 15 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/context.ts: -------------------------------------------------------------------------------- 1 | import { Status } from './status.js' 2 | 3 | export type Context = { 4 | ancestors: Array 5 | descendants: Array 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/emoji.ts: -------------------------------------------------------------------------------- 1 | export type Emoji = { 2 | shortcode: string 3 | static_url: string 4 | url: string 5 | visible_in_picker: boolean 6 | category?: string 7 | } 8 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/field.ts: -------------------------------------------------------------------------------- 1 | export type Field = { 2 | name: string 3 | value: string 4 | verified_at: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/filter.ts: -------------------------------------------------------------------------------- 1 | export type Filter = { 2 | id: string 3 | phrase: string 4 | context: Array 5 | expires_at: string | null 6 | irreversible: boolean 7 | whole_word: boolean 8 | } 9 | 10 | export type FilterContext = string 11 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/instance.ts: -------------------------------------------------------------------------------- 1 | import { URLs } from './urls.js' 2 | import { Stats } from './stats.js' 3 | import { Account } from './account.js' 4 | 5 | export type Instance = { 6 | account_domain: string 7 | approval_required: boolean 8 | configuration: { 9 | statuses: { 10 | max_characters: number 11 | max_media_attachments: number 12 | characters_reserved_per_url: number 13 | } 14 | media_attachments: { 15 | supported_mime_types: Array 16 | image_size_limit: number 17 | image_matrix_limit: number 18 | video_size_limit: number 19 | video_frame_limit: number 20 | video_matrix_limit: number 21 | } 22 | polls: { 23 | max_options: number 24 | max_characters_per_option: number 25 | min_expiration: number 26 | max_expiration: number 27 | } 28 | } 29 | contact_account?: Account 30 | description: string 31 | email: string 32 | invites_enabled: boolean 33 | languages: Array 34 | max_toot_chars: number 35 | registrations: boolean 36 | stats: Stats 37 | thumbnail: string | null 38 | title: string 39 | uri: string 40 | urls: URLs 41 | version: string 42 | } 43 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/list.ts: -------------------------------------------------------------------------------- 1 | export type List = { 2 | id: string 3 | title: string 4 | replies_policy?: RepliesPolicy 5 | } 6 | 7 | export type RepliesPolicy = 'followed' | 'list' | 'none' 8 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/marker.ts: -------------------------------------------------------------------------------- 1 | export type Marker = { 2 | home: InnerMarker 3 | notifications: InnerMarker 4 | } 5 | 6 | type InnerMarker = { 7 | last_read_id: string 8 | version: number 9 | updated_at: string 10 | } 11 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/mention.ts: -------------------------------------------------------------------------------- 1 | export type Mention = { 2 | id: string 3 | username: string 4 | url: string 5 | acct: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/notification.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | 4 | export type Notification = { 5 | account: Account 6 | created_at: string 7 | id: string 8 | status?: Status 9 | type: NotificationType 10 | } 11 | 12 | export type NotificationType = string 13 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/poll.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | 3 | export type Poll = { 4 | id: string 5 | expires_at: string | null 6 | expired: boolean 7 | multiple: boolean 8 | votes_count: number 9 | options: Array 10 | voted: boolean 11 | emojis: Array 12 | } 13 | 14 | export type PollOption = { 15 | title: string 16 | votes_count: number | null 17 | } 18 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/preferences.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type Preferences = { 4 | 'posting:default:visibility': StatusVisibility 5 | 'posting:default:sensitive': boolean 6 | 'posting:default:language': string | null 7 | 'reading:expand:media': 'default' | 'show_all' | 'hide_all' 8 | 'reading:expand:spoilers': boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/relationship.ts: -------------------------------------------------------------------------------- 1 | export type Relationship = { 2 | id: string 3 | following: boolean 4 | followed_by: boolean 5 | blocking: boolean 6 | blocked_by: boolean 7 | muting: boolean 8 | muting_notifications: boolean 9 | requested: boolean 10 | domain_blocking: boolean 11 | showing_reblogs: boolean 12 | endorsed: boolean 13 | notifying: boolean 14 | note: string 15 | } 16 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/report.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | 3 | export type Report = { 4 | id: string 5 | action_taken: boolean 6 | action_taken_at: string | null 7 | category: Category 8 | comment: string 9 | forwarded: boolean 10 | status_ids: Array | null 11 | rule_ids: Array | null 12 | target_account: Account 13 | } 14 | 15 | export type Category = 'spam' | 'violation' | 'other' 16 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/results.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | import { Tag } from './tag.js' 4 | 5 | export type Results = { 6 | accounts: Array 7 | statuses: Array 8 | hashtags: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/role.ts: -------------------------------------------------------------------------------- 1 | export type Role = { 2 | name: string 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/scheduled_status.ts: -------------------------------------------------------------------------------- 1 | import { Attachment } from './attachment.js' 2 | import { StatusParams } from './status_params.js' 3 | 4 | export type ScheduledStatus = { 5 | id: string 6 | scheduled_at: string 7 | params: StatusParams 8 | media_attachments: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/source.ts: -------------------------------------------------------------------------------- 1 | import { Field } from './field.js' 2 | 3 | export type Source = { 4 | privacy: string | null 5 | sensitive: boolean | null 6 | language: string | null 7 | note: string 8 | fields?: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/stats.ts: -------------------------------------------------------------------------------- 1 | export type Stats = { 2 | user_count: number 3 | status_count: number 4 | domain_count: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/status.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Application } from './application.js' 3 | import { Attachment } from './attachment.js' 4 | import { Mention } from './mention.js' 5 | import { Emoji } from './emoji.js' 6 | import { Card } from './card.js' 7 | import { Poll } from './poll.js' 8 | 9 | export type Status = { 10 | id: string 11 | uri: string 12 | url?: string 13 | account: Account 14 | in_reply_to_id: string | null 15 | in_reply_to_account_id: string | null 16 | reblog: Status | null 17 | content: string 18 | created_at: string 19 | emojis: Array 20 | replies_count: number 21 | reblogs_count: number 22 | favourites_count: number 23 | reblogged: boolean | null 24 | favourited: boolean | null 25 | muted: boolean | null 26 | sensitive: boolean 27 | spoiler_text: string 28 | visibility: StatusVisibility 29 | media_attachments: Array 30 | mentions: Array 31 | tags: Array 32 | card: Card | null 33 | poll: Poll | null 34 | application: Application | null 35 | language: string | null 36 | pinned: boolean | null 37 | bookmarked?: boolean 38 | } 39 | 40 | export type StatusTag = { 41 | name: string 42 | url: string 43 | } 44 | 45 | export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct' 46 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/status_params.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type StatusParams = { 4 | text: string 5 | in_reply_to_id: string | null 6 | media_ids: Array | null 7 | sensitive: boolean | null 8 | spoiler_text: string | null 9 | visibility: StatusVisibility | null 10 | scheduled_at: string | null 11 | application_id: number 12 | } 13 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/status_source.ts: -------------------------------------------------------------------------------- 1 | export type StatusSource = { 2 | id: string 3 | text: string 4 | spoiler_text: string 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/tag.ts: -------------------------------------------------------------------------------- 1 | export type Tag = { 2 | name: string 3 | url: string 4 | following?: boolean 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/token.ts: -------------------------------------------------------------------------------- 1 | export type Token = { 2 | access_token: string 3 | token_type: string 4 | scope: string 5 | created_at: number 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entities/urls.ts: -------------------------------------------------------------------------------- 1 | export type URLs = { 2 | streaming_api: string 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/entity.ts: -------------------------------------------------------------------------------- 1 | import * as account from './entities/account.js' 2 | import * as application from './entities/application.js' 3 | import * as attachment from './entities/attachment.js' 4 | import * as card from './entities/card.js' 5 | import * as context from './entities/context.js' 6 | import * as emoji from './entities/emoji.js' 7 | import * as field from './entities/field.js' 8 | import * as filter from './entities/filter.js' 9 | import * as instance from './entities/instance.js' 10 | import * as list from './entities/list.js' 11 | import * as marker from './entities/marker.js' 12 | import * as mentition from './entities/mention.js' 13 | import * as notification from './entities/notification.js' 14 | import * as poll from './entities/poll.js' 15 | import * as preferences from './entities/preferences.js' 16 | import * as relationship from './entities/relationship.js' 17 | import * as report from './entities/report.js' 18 | import * as results from './entities/results.js' 19 | import * as role from './entities/role.js' 20 | import * as scheduled_status from './entities/scheduled_status.js' 21 | import * as source from './entities/source.js' 22 | import * as stats from './entities/stats.js' 23 | import * as status from './entities/status.js' 24 | import * as status_params from './entities/status_params.js' 25 | import * as status_source from './entities/status_source.js' 26 | import * as tag from './entities/tag.js' 27 | import * as token from './entities/token.js' 28 | import * as urls from './entities/urls.js' 29 | 30 | export namespace Entity { 31 | export type Account = account.Account 32 | export type Application = application.Application 33 | export type Attachment = attachment.Attachment 34 | export type Card = card.Card 35 | export type Context = context.Context 36 | export type Emoji = emoji.Emoji 37 | export type Field = field.Field 38 | export type Filter = filter.Filter 39 | export type Instance = instance.Instance 40 | export type List = list.List 41 | export type Marker = marker.Marker 42 | export type Mention = mentition.Mention 43 | export type Notification = notification.Notification 44 | export type NotificationType = notification.NotificationType 45 | export type Poll = poll.Poll 46 | export type PollOption = poll.PollOption 47 | export type Preferences = preferences.Preferences 48 | export type Relationship = relationship.Relationship 49 | export type Report = report.Report 50 | export type Results = results.Results 51 | export type Role = role.Role 52 | export type ScheduledStatus = scheduled_status.ScheduledStatus 53 | export type Source = source.Source 54 | export type Stats = stats.Stats 55 | export type Status = status.Status 56 | export type StatusParams = status_params.StatusParams 57 | export type StatusSource = status_source.StatusSource 58 | export type Tag = tag.Tag 59 | export type Token = token.Token 60 | export type URLs = urls.URLs 61 | } 62 | 63 | export default Entity 64 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/notification.ts: -------------------------------------------------------------------------------- 1 | import GotosocialEntity from './entity.js' 2 | 3 | namespace GotosocialNotificationType { 4 | export const Follow: GotosocialEntity.NotificationType = 'follow' 5 | export const FollowRequest: GotosocialEntity.NotificationType = 'follow_request' 6 | export const Mention: GotosocialEntity.NotificationType = 'mention' 7 | export const Reblog: GotosocialEntity.NotificationType = 'reblog' 8 | export const Favourite: GotosocialEntity.NotificationType = 'favourite' 9 | export const Poll: GotosocialEntity.NotificationType = 'poll' 10 | export const Status: GotosocialEntity.NotificationType = 'status' 11 | } 12 | 13 | export default GotosocialNotificationType 14 | -------------------------------------------------------------------------------- /megalodon/src/gotosocial/oauth.ts: -------------------------------------------------------------------------------- 1 | import OAuth from '@/oauth.js' 2 | 3 | export type AppDataFromServer = { 4 | id: string 5 | name: string 6 | website: string | null 7 | redirect_uri: string 8 | client_id: string 9 | client_secret: string 10 | } 11 | 12 | export type TokenDataFromServer = { 13 | access_token: string 14 | token_type: string 15 | scope: string 16 | created_at: number 17 | } 18 | 19 | export function toAppData(appData: AppDataFromServer): OAuth.AppData { 20 | return { 21 | id: appData.id, 22 | name: appData.name, 23 | website: appData.website, 24 | redirect_uri: appData.redirect_uri, 25 | client_id: appData.client_id, 26 | client_secret: appData.client_secret, 27 | url: null, 28 | session_token: null 29 | } 30 | } 31 | 32 | export function toTokenData(tokenData: TokenDataFromServer): OAuth.TokenData { 33 | return { 34 | access_token: tokenData.access_token, 35 | token_type: tokenData.token_type, 36 | scope: tokenData.scope, 37 | created_at: tokenData.created_at, 38 | expires_in: null, 39 | refresh_token: null 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /megalodon/src/index.ts: -------------------------------------------------------------------------------- 1 | import Response from './response.js' 2 | import OAuth from './oauth.js' 3 | import { isCancel, RequestCanceledError } from './cancel.js' 4 | import generator, { MegalodonInterface, WebSocketInterface } from './megalodon.js' 5 | import { detector } from './detector.js' 6 | import Mastodon from './mastodon.js' 7 | import Pleroma from './pleroma.js' 8 | import Pixelfed from './pixelfed.js' 9 | import Firefish from './firefish.js' 10 | import Gotosocial from './gotosocial.js' 11 | import Entity from './entity.js' 12 | import NotificationType from './notification.js' 13 | import FilterContext from './filter_context.js' 14 | 15 | export { 16 | Response, 17 | OAuth, 18 | RequestCanceledError, 19 | isCancel, 20 | detector, 21 | MegalodonInterface, 22 | WebSocketInterface, 23 | NotificationType, 24 | FilterContext, 25 | Mastodon, 26 | Pleroma, 27 | Pixelfed, 28 | Firefish, 29 | Gotosocial, 30 | Entity 31 | } 32 | 33 | export default generator 34 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/account.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | import { Field } from './field.js' 3 | import { Source } from './source.js' 4 | import { Role } from './role.js' 5 | 6 | export type Account = { 7 | id: string 8 | username: string 9 | acct: string 10 | display_name: string 11 | locked: boolean 12 | discoverable?: boolean 13 | group: boolean | null 14 | noindex: boolean | null 15 | suspended: boolean | null 16 | limited: boolean | null 17 | created_at: string 18 | followers_count: number 19 | following_count: number 20 | statuses_count: number 21 | note: string 22 | url: string 23 | avatar: string 24 | avatar_static: string 25 | header: string 26 | header_static: string 27 | emojis: Array 28 | moved: Account | null 29 | fields: Array 30 | bot: boolean 31 | source?: Source 32 | role?: Role 33 | mute_expires_at?: string 34 | } 35 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/activity.ts: -------------------------------------------------------------------------------- 1 | export type Activity = { 2 | week: string 3 | statuses: string 4 | logins: string 5 | registrations: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/announcement.ts: -------------------------------------------------------------------------------- 1 | import { StatusTag } from './status.js' 2 | import { Emoji } from './emoji.js' 3 | 4 | export type Announcement = { 5 | id: string 6 | content: string 7 | starts_at: string | null 8 | ends_at: string | null 9 | published: boolean 10 | all_day: boolean 11 | published_at: string 12 | updated_at: string 13 | read: boolean | null 14 | mentions: Array 15 | statuses: Array 16 | tags: Array 17 | emojis: Array 18 | reactions: Array 19 | } 20 | 21 | export type AnnouncementAccount = { 22 | id: string 23 | username: string 24 | url: string 25 | acct: string 26 | } 27 | 28 | export type AnnouncementStatus = { 29 | id: string 30 | url: string 31 | } 32 | 33 | export type AnnouncementReaction = { 34 | name: string 35 | count: number 36 | me: boolean | null 37 | url: string | null 38 | static_url: string | null 39 | } 40 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/application.ts: -------------------------------------------------------------------------------- 1 | export type Application = { 2 | name: string 3 | website?: string | null 4 | vapid_key?: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/async_attachment.ts: -------------------------------------------------------------------------------- 1 | import { Meta } from './attachment.js' 2 | 3 | export type AsyncAttachment = { 4 | id: string 5 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 6 | url: string | null 7 | remote_url: string | null 8 | preview_url: string 9 | text_url: string | null 10 | meta: Meta | null 11 | description: string | null 12 | blurhash: string | null 13 | } 14 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/attachment.ts: -------------------------------------------------------------------------------- 1 | export type Sub = { 2 | // For Image, Gifv, and Video 3 | width?: number 4 | height?: number 5 | size?: string 6 | aspect?: number 7 | 8 | // For Gifv and Video 9 | frame_rate?: string 10 | 11 | // For Audio, Gifv, and Video 12 | duration?: number 13 | bitrate?: number 14 | } 15 | 16 | export type Focus = { 17 | x: number 18 | y: number 19 | } 20 | 21 | export type Meta = { 22 | original?: Sub 23 | small?: Sub 24 | focus?: Focus 25 | length?: string 26 | duration?: number 27 | fps?: number 28 | size?: string 29 | width?: number 30 | height?: number 31 | aspect?: number 32 | audio_encode?: string 33 | audio_bitrate?: string 34 | audio_channel?: string 35 | } 36 | 37 | export type Attachment = { 38 | id: string 39 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 40 | url: string 41 | remote_url: string | null 42 | preview_url: string | null 43 | text_url: string | null 44 | meta: Meta | null 45 | description: string | null 46 | blurhash: string | null 47 | } 48 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/card.ts: -------------------------------------------------------------------------------- 1 | export type Card = { 2 | url: string 3 | title: string 4 | description: string 5 | type: 'link' | 'photo' | 'video' | 'rich' 6 | image: string | null 7 | author_name: string 8 | author_url: string 9 | provider_name: string 10 | provider_url: string 11 | html: string 12 | width: number 13 | height: number 14 | embed_url: string 15 | blurhash: string | null 16 | } 17 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/context.ts: -------------------------------------------------------------------------------- 1 | import { Status } from './status.js' 2 | 3 | export type Context = { 4 | ancestors: Array 5 | descendants: Array 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/conversation.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | 4 | export type Conversation = { 5 | id: string 6 | accounts: Array 7 | last_status: Status | null 8 | unread: boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/emoji.ts: -------------------------------------------------------------------------------- 1 | export type Emoji = { 2 | shortcode: string 3 | static_url: string 4 | url: string 5 | visible_in_picker: boolean 6 | category?: string 7 | } 8 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/featured_tag.ts: -------------------------------------------------------------------------------- 1 | export type FeaturedTag = { 2 | id: string 3 | name: string 4 | statuses_count: number 5 | last_status_at: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/field.ts: -------------------------------------------------------------------------------- 1 | export type Field = { 2 | name: string 3 | value: string 4 | verified_at: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/filter.ts: -------------------------------------------------------------------------------- 1 | export type Filter = { 2 | id: string 3 | phrase: string 4 | context: Array 5 | expires_at: string | null 6 | irreversible: boolean 7 | whole_word: boolean 8 | } 9 | 10 | export type FilterContext = string 11 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/history.ts: -------------------------------------------------------------------------------- 1 | export type History = { 2 | day: string 3 | uses: number 4 | accounts: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/identity_proof.ts: -------------------------------------------------------------------------------- 1 | export type IdentityProof = { 2 | provider: string 3 | provider_username: string 4 | updated_at: string 5 | proof_url: string 6 | profile_url: string 7 | } 8 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/instance.ts: -------------------------------------------------------------------------------- 1 | import { URLs } from './urls.js' 2 | import { Stats } from './stats.js' 3 | import { Account } from './account.js' 4 | 5 | export type Instance = { 6 | uri: string 7 | title: string 8 | description: string 9 | email: string 10 | version: string 11 | thumbnail: string | null 12 | urls: URLs 13 | stats: Stats 14 | languages: Array 15 | registrations: boolean 16 | approval_required: boolean 17 | invites_enabled: boolean 18 | max_toot_chars?: number 19 | configuration: { 20 | statuses: { 21 | max_characters: number 22 | max_media_attachments: number 23 | characters_reserved_per_url: number 24 | } 25 | media_attachments: { 26 | supported_mime_types: Array 27 | image_size_limit: number 28 | image_matrix_limit: number 29 | video_size_limit: number 30 | video_frame_limit: number 31 | video_matrix_limit: number 32 | } 33 | polls: { 34 | max_options: number 35 | max_characters_per_option: number 36 | min_expiration: number 37 | max_expiration: number 38 | } 39 | } 40 | contact_account: Account 41 | rules: Array 42 | } 43 | 44 | export type InstanceRule = { 45 | id: string 46 | text: string 47 | } 48 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/list.ts: -------------------------------------------------------------------------------- 1 | export type List = { 2 | id: string 3 | title: string 4 | replies_policy: RepliesPolicy 5 | } 6 | 7 | export type RepliesPolicy = 'followed' | 'list' | 'none' 8 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/marker.ts: -------------------------------------------------------------------------------- 1 | export type Marker = { 2 | home: { 3 | last_read_id: string 4 | version: number 5 | updated_at: string 6 | } 7 | notifications: { 8 | last_read_id: string 9 | version: number 10 | updated_at: string 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/mention.ts: -------------------------------------------------------------------------------- 1 | export type Mention = { 2 | id: string 3 | username: string 4 | url: string 5 | acct: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/notification.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | 4 | export type Notification = { 5 | account: Account 6 | created_at: string 7 | id: string 8 | status?: Status 9 | type: NotificationType 10 | } 11 | 12 | export type NotificationType = string 13 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/poll.ts: -------------------------------------------------------------------------------- 1 | export type Poll = { 2 | id: string 3 | expires_at: string | null 4 | expired: boolean 5 | multiple: boolean 6 | votes_count: number 7 | options: Array 8 | voted: boolean 9 | } 10 | 11 | export type PollOption = { 12 | title: string 13 | votes_count: number | null 14 | } 15 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/preferences.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type Preferences = { 4 | 'posting:default:visibility': StatusVisibility 5 | 'posting:default:sensitive': boolean 6 | 'posting:default:language': string | null 7 | 'reading:expand:media': 'default' | 'show_all' | 'hide_all' 8 | 'reading:expand:spoilers': boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/push_subscription.ts: -------------------------------------------------------------------------------- 1 | export type Alerts = { 2 | follow: boolean 3 | favourite: boolean 4 | mention: boolean 5 | reblog: boolean 6 | poll: boolean 7 | } 8 | 9 | export type PushSubscription = { 10 | id: string 11 | endpoint: string 12 | server_key: string 13 | alerts: Alerts 14 | } 15 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/relationship.ts: -------------------------------------------------------------------------------- 1 | export type Relationship = { 2 | id: string 3 | following: boolean 4 | followed_by: boolean 5 | blocking: boolean 6 | blocked_by: boolean 7 | muting: boolean 8 | muting_notifications: boolean 9 | requested: boolean 10 | domain_blocking: boolean 11 | showing_reblogs: boolean 12 | endorsed: boolean 13 | notifying: boolean 14 | note: string 15 | languages: Array 16 | } 17 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/report.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | 3 | export type Report = { 4 | id: string 5 | action_taken: boolean 6 | action_taken_at: string | null 7 | category: Category 8 | comment: string 9 | forwarded: boolean 10 | status_ids: Array | null 11 | rule_ids: Array | null 12 | target_account: Account 13 | } 14 | 15 | export type Category = 'spam' | 'violation' | 'other' 16 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/results.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | import { Tag } from './tag.js' 4 | 5 | export type Results = { 6 | accounts: Array 7 | statuses: Array 8 | hashtags: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/role.ts: -------------------------------------------------------------------------------- 1 | export type Role = { 2 | name: string 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/scheduled_status.ts: -------------------------------------------------------------------------------- 1 | import { Attachment } from './attachment.js' 2 | import { StatusParams } from './status_params.js' 3 | 4 | export type ScheduledStatus = { 5 | id: string 6 | scheduled_at: string 7 | params: StatusParams 8 | media_attachments: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/source.ts: -------------------------------------------------------------------------------- 1 | import { Field } from './field.js' 2 | 3 | export type Source = { 4 | privacy: string | null 5 | sensitive: boolean | null 6 | language: string | null 7 | note: string 8 | fields: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/stats.ts: -------------------------------------------------------------------------------- 1 | export type Stats = { 2 | user_count: number 3 | status_count: number 4 | domain_count: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/status.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Application } from './application.js' 3 | import { Attachment } from './attachment.js' 4 | import { Mention } from './mention.js' 5 | import { Emoji } from './emoji.js' 6 | import { Card } from './card.js' 7 | import { Poll } from './poll.js' 8 | 9 | export type Status = { 10 | id: string 11 | uri: string 12 | url: string 13 | account: Account 14 | in_reply_to_id: string | null 15 | in_reply_to_account_id: string | null 16 | reblog: Status | null 17 | content: string 18 | created_at: string 19 | edited_at: string | null 20 | emojis: Emoji[] 21 | replies_count: number 22 | reblogs_count: number 23 | favourites_count: number 24 | reblogged: boolean | null 25 | favourited: boolean | null 26 | muted: boolean | null 27 | sensitive: boolean 28 | spoiler_text: string 29 | visibility: StatusVisibility 30 | media_attachments: Array 31 | mentions: Array 32 | tags: Array 33 | card: Card | null 34 | poll: Poll | null 35 | application: Application | null 36 | language: string | null 37 | pinned: boolean | null 38 | bookmarked?: boolean 39 | // These parameters are unique parameters in fedibird.com for quote. 40 | quote_id?: string 41 | quote?: Status | null 42 | } 43 | 44 | export type StatusTag = { 45 | name: string 46 | url: string 47 | } 48 | 49 | export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct' 50 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/status_params.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type StatusParams = { 4 | text: string 5 | in_reply_to_id: string | null 6 | media_ids: Array | null 7 | sensitive: boolean | null 8 | spoiler_text: string | null 9 | visibility: StatusVisibility | null 10 | scheduled_at: string | null 11 | application_id: number 12 | } 13 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/status_source.ts: -------------------------------------------------------------------------------- 1 | export type StatusSource = { 2 | id: string 3 | text: string 4 | spoiler_text: string 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/tag.ts: -------------------------------------------------------------------------------- 1 | import { History } from './history.js' 2 | 3 | export type Tag = { 4 | name: string 5 | url: string 6 | history: Array 7 | following?: boolean 8 | } 9 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/token.ts: -------------------------------------------------------------------------------- 1 | export type Token = { 2 | access_token: string 3 | token_type: string 4 | scope: string 5 | created_at: number 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/entities/urls.ts: -------------------------------------------------------------------------------- 1 | export type URLs = { 2 | streaming_api: string 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/notification.ts: -------------------------------------------------------------------------------- 1 | import MastodonEntity from './entity.js' 2 | 3 | namespace MastodonNotificationType { 4 | export const Mention: MastodonEntity.NotificationType = 'mention' 5 | export const Reblog: MastodonEntity.NotificationType = 'reblog' 6 | export const Favourite: MastodonEntity.NotificationType = 'favourite' 7 | export const Follow: MastodonEntity.NotificationType = 'follow' 8 | export const Poll: MastodonEntity.NotificationType = 'poll' 9 | export const FollowRequest: MastodonEntity.NotificationType = 'follow_request' 10 | export const Status: MastodonEntity.NotificationType = 'status' 11 | export const Update: MastodonEntity.NotificationType = 'update' 12 | export const AdminSignup: MastodonEntity.NotificationType = 'admin.sign_up' 13 | export const AdminReport: MastodonEntity.NotificationType = 'admin.report' 14 | } 15 | 16 | export default MastodonNotificationType 17 | -------------------------------------------------------------------------------- /megalodon/src/mastodon/oauth.ts: -------------------------------------------------------------------------------- 1 | import OAuth from '@/oauth.js' 2 | 3 | export type AppDataFromServer = { 4 | id: string 5 | name: string 6 | website: string | null 7 | redirect_uri: string 8 | client_id: string 9 | client_secret: string 10 | } 11 | 12 | export type TokenDataFromServer = { 13 | access_token: string 14 | token_type: string 15 | scope: string 16 | created_at: number 17 | } 18 | 19 | export function toAppData(appData: AppDataFromServer): OAuth.AppData { 20 | return { 21 | id: appData.id, 22 | name: appData.name, 23 | website: appData.website, 24 | redirect_uri: appData.redirect_uri, 25 | client_id: appData.client_id, 26 | client_secret: appData.client_secret, 27 | url: null, 28 | session_token: null 29 | } 30 | } 31 | 32 | export function toTokenData(tokenData: TokenDataFromServer): OAuth.TokenData { 33 | return { 34 | access_token: tokenData.access_token, 35 | token_type: tokenData.token_type, 36 | scope: tokenData.scope, 37 | created_at: tokenData.created_at, 38 | expires_in: null, 39 | refresh_token: null 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /megalodon/src/notification.ts: -------------------------------------------------------------------------------- 1 | import Entity from './entity.js' 2 | 3 | namespace NotificationType { 4 | export const Follow: Entity.NotificationType = 'follow' 5 | export const Favourite: Entity.NotificationType = 'favourite' 6 | export const Reblog: Entity.NotificationType = 'reblog' 7 | export const Mention: Entity.NotificationType = 'mention' 8 | export const Reaction: Entity.NotificationType = 'reaction' 9 | export const FollowRequest: Entity.NotificationType = 'follow_request' 10 | export const Status: Entity.NotificationType = 'status' 11 | export const PollVote: Entity.NotificationType = 'poll_vote' 12 | export const PollExpired: Entity.NotificationType = 'poll_expired' 13 | export const Update: Entity.NotificationType = 'update' 14 | export const Move: Entity.NotificationType = 'move' 15 | export const AdminSignup: Entity.NotificationType = 'admin.sign_up' 16 | export const AdminReport: Entity.NotificationType = 'admin.report' 17 | } 18 | 19 | export class UnknownNotificationTypeError extends Error { 20 | constructor() { 21 | super() 22 | Object.setPrototypeOf(this, UnknownNotificationTypeError.prototype) 23 | } 24 | } 25 | 26 | export default NotificationType 27 | -------------------------------------------------------------------------------- /megalodon/src/oauth.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * OAuth 3 | * Response data when oauth request. 4 | **/ 5 | namespace OAuth { 6 | export type AppData = { 7 | id: string 8 | name: string 9 | website: string | null 10 | redirect_uri: string | null 11 | client_id: string 12 | client_secret: string 13 | url: string | null 14 | session_token: string | null 15 | } 16 | 17 | export type TokenData = { 18 | access_token: string 19 | token_type: string 20 | scope: string | null 21 | created_at: number | null 22 | expires_in: number | null 23 | refresh_token: string | null 24 | } 25 | } 26 | 27 | export default OAuth 28 | -------------------------------------------------------------------------------- /megalodon/src/parse_link_header.ts: -------------------------------------------------------------------------------- 1 | // Refs: https://gist.github.com/Honkalonkalooohhhhh/dfe8a3721f77ded62ff8038ead2afd77 2 | export function parseLinkHeader(header: string): LinkHeader { 3 | const links: LinkHeader = {} 4 | 5 | if (header.length === 0) { 6 | throw new Error('input must not be of zero length') 7 | } 8 | 9 | const parts = header.split(',') 10 | // Parse each part into a named link 11 | parts.forEach(part => { 12 | const section: string[] = part.split(';') 13 | 14 | if (section.length !== 2) { 15 | throw new Error("section could not be split on ';'") 16 | } 17 | const url = section[0].replace(/<(.*)>/, '$1').trim() 18 | const name = section[1].replace(/rel="(.*)"/, '$1').trim() 19 | links[name] = url 20 | }) 21 | 22 | return links 23 | } 24 | 25 | export type LinkHeader = { [key: string]: string } 26 | -------------------------------------------------------------------------------- /megalodon/src/parser.ts: -------------------------------------------------------------------------------- 1 | import { EventEmitter } from 'events' 2 | import Entity from './entity.js' 3 | 4 | /** 5 | * Parser 6 | * Parse response data in streaming. 7 | **/ 8 | export class Parser extends EventEmitter { 9 | private message: string 10 | 11 | constructor() { 12 | super() 13 | this.message = '' 14 | } 15 | 16 | public parse(chunk: string) { 17 | // skip heartbeats 18 | if (chunk === ':thump\n') { 19 | this.emit('heartbeat', {}) 20 | return 21 | } 22 | 23 | this.message += chunk 24 | chunk = this.message 25 | 26 | const size: number = chunk.length 27 | let start: number = 0 28 | let offset: number = 0 29 | let curr: string | undefined 30 | let next: string | undefined 31 | 32 | while (offset < size) { 33 | curr = chunk[offset] 34 | next = chunk[offset + 1] 35 | 36 | if (curr === '\n' && next === '\n') { 37 | const piece: string = chunk.slice(start, offset) 38 | 39 | offset += 2 40 | start = offset 41 | 42 | if (!piece.length) continue // empty object 43 | 44 | const root: Array = piece.split('\n') 45 | 46 | // should never happen, as long as mastodon doesn't change API messages 47 | if (root.length !== 2) continue 48 | 49 | // remove event and data markers 50 | const event: string = root[0].substr(7) 51 | const data: string = root[1].substr(6) 52 | 53 | let jsonObj = {} 54 | try { 55 | jsonObj = JSON.parse(data) 56 | } catch (err) { 57 | // delete event does not have json object 58 | if (event !== 'delete') { 59 | this.emit('error', new Error(`Error parsing API reply: '${piece}', error message: '${err}'`)) 60 | continue 61 | } 62 | } 63 | switch (event) { 64 | case 'update': 65 | this.emit('update', jsonObj as Entity.Status) 66 | break 67 | case 'notification': 68 | this.emit('notification', jsonObj as Entity.Notification) 69 | break 70 | case 'conversation': 71 | this.emit('conversation', jsonObj as Entity.Conversation) 72 | break 73 | case 'delete': 74 | // When delete, data is an ID of the deleted status 75 | this.emit('delete', data) 76 | break 77 | default: 78 | this.emit('error', new Error(`Unknown event has received: ${event}`)) 79 | continue 80 | } 81 | } 82 | offset++ 83 | } 84 | this.message = chunk.slice(start, size) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/account.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | import { Field } from './field.js' 3 | import { Source } from './source.js' 4 | 5 | export type Account = { 6 | id: string 7 | username: string 8 | acct: string 9 | display_name: string 10 | discoverable?: boolean 11 | locked: boolean 12 | followers_count: number 13 | following_count: number 14 | statuses_count: number 15 | note: string 16 | url: string 17 | avatar: string 18 | created_at: string 19 | avatar_static: string 20 | bot: boolean 21 | emojis: Array 22 | fields: Array 23 | header: string 24 | header_static: string 25 | last_status_at: string | null 26 | source?: Source 27 | } 28 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/announcement.ts: -------------------------------------------------------------------------------- 1 | import { StatusTag } from './status.js' 2 | import { Emoji } from './emoji.js' 3 | 4 | export type Announcement = { 5 | id: string 6 | content: string 7 | starts_at: string | null 8 | ends_at: string | null 9 | published: boolean 10 | all_day: boolean 11 | published_at: string 12 | updated_at: string 13 | read: boolean | null 14 | mentions: Array 15 | statuses: Array 16 | tags: Array 17 | emojis: Array 18 | reactions: Array 19 | } 20 | 21 | export type AnnouncementAccount = { 22 | id: string 23 | username: string 24 | url: string 25 | acct: string 26 | } 27 | 28 | export type AnnouncementStatus = { 29 | id: string 30 | url: string 31 | } 32 | 33 | export type AnnouncementReaction = { 34 | name: string 35 | count: number 36 | me: boolean | null 37 | url: string | null 38 | static_url: string | null 39 | } 40 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/application.ts: -------------------------------------------------------------------------------- 1 | export type Application = { 2 | name: string 3 | website?: string | null 4 | vapid_key?: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/async_attachment.ts: -------------------------------------------------------------------------------- 1 | import { Meta } from './attachment.js' 2 | 3 | export type AsyncAttachment = { 4 | id: string 5 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 6 | url: string | null 7 | remote_url: string | null 8 | preview_url: string 9 | text_url: string | null 10 | meta: Meta | null 11 | description: string | null 12 | blurhash: string | null 13 | } 14 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/attachment.ts: -------------------------------------------------------------------------------- 1 | export type Sub = { 2 | // For Image, Gifv, and Video 3 | width?: number 4 | height?: number 5 | size?: string 6 | aspect?: number 7 | 8 | // For Gifv and Video 9 | frame_rate?: string 10 | 11 | // For Audio, Gifv, and Video 12 | duration?: number 13 | bitrate?: number 14 | } 15 | 16 | export type Focus = { 17 | x: number 18 | y: number 19 | } 20 | 21 | export type Meta = { 22 | original?: Sub 23 | small?: Sub 24 | focus?: Focus 25 | length?: string 26 | duration?: number 27 | fps?: number 28 | size?: string 29 | width?: number 30 | height?: number 31 | aspect?: number 32 | audio_encode?: string 33 | audio_bitrate?: string 34 | audio_channel?: string 35 | } 36 | 37 | export type Attachment = { 38 | id: string 39 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 40 | url: string 41 | remote_url: string | null 42 | preview_url: string | null 43 | text_url: string | null 44 | meta: Meta | null 45 | description: string | null 46 | blurhash: string | null 47 | } 48 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/context.ts: -------------------------------------------------------------------------------- 1 | import { Status } from './status.js' 2 | 3 | export type Context = { 4 | ancestors: Array 5 | descendants: Array 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/conversation.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | 4 | export type Conversation = { 5 | id: string 6 | accounts: Array 7 | last_status: Status | null 8 | unread: boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/emoji.ts: -------------------------------------------------------------------------------- 1 | export type Emoji = { 2 | shortcode: string 3 | static_url: string 4 | url: string 5 | visible_in_picker: boolean 6 | category?: string 7 | } 8 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/field.ts: -------------------------------------------------------------------------------- 1 | export type Field = { 2 | name: string 3 | value: string 4 | verified_at: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/filter.ts: -------------------------------------------------------------------------------- 1 | export type Filter = { 2 | id: string 3 | phrase: string 4 | context: Array 5 | expires_at: string | null 6 | irreversible: boolean 7 | whole_word: boolean 8 | } 9 | 10 | export type FilterContext = string 11 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/history.ts: -------------------------------------------------------------------------------- 1 | export type History = { 2 | day: string 3 | uses: number 4 | accounts: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/instance.ts: -------------------------------------------------------------------------------- 1 | import { Stats } from './stats.js' 2 | import { Account } from './account.js' 3 | 4 | export type Instance = { 5 | uri: string 6 | title: string 7 | short_description: string 8 | description: string 9 | email: string 10 | version: string 11 | thumbnail: string | null 12 | stats: Stats 13 | languages: Array 14 | registrations: boolean 15 | approval_required: boolean 16 | configuration: { 17 | statuses: { 18 | max_characters: number 19 | max_media_attachments: number 20 | characters_reserved_per_url: number 21 | } 22 | media_attachments: { 23 | supported_mime_types: Array 24 | image_size_limit: number 25 | image_matrix_limit: number 26 | video_size_limit: number 27 | video_frame_limit: number 28 | video_matrix_limit: number 29 | } 30 | polls: { 31 | max_options: number 32 | max_characters_per_option: number 33 | min_expiration: number 34 | max_expiration: number 35 | } 36 | } 37 | contact_account: Account 38 | rules: Array 39 | } 40 | 41 | export type InstanceRule = { 42 | id: string 43 | text: string 44 | } 45 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/marker.ts: -------------------------------------------------------------------------------- 1 | export type Marker = { 2 | home: { 3 | last_read_id: string 4 | version: number 5 | updated_at: string 6 | } 7 | notifications: { 8 | last_read_id: string 9 | version: number 10 | updated_at: string 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/mention.ts: -------------------------------------------------------------------------------- 1 | export type Mention = { 2 | id: string 3 | username: string 4 | url: string 5 | acct: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/notification.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | 4 | export type Notification = { 5 | account: Account 6 | created_at: string 7 | id: string 8 | status?: Status 9 | type: NotificationType 10 | } 11 | 12 | export type NotificationType = string 13 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/poll.ts: -------------------------------------------------------------------------------- 1 | export type Poll = { 2 | id: string 3 | expires_at: string | null 4 | expired: boolean 5 | multiple: boolean 6 | votes_count: number 7 | options: Array 8 | voted: boolean 9 | } 10 | 11 | export type PollOption = { 12 | title: string 13 | votes_count: number | null 14 | } 15 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/preferences.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type Preferences = { 4 | 'posting:default:visibility': StatusVisibility 5 | 'posting:default:sensitive': boolean 6 | 'posting:default:language': string | null 7 | 'reading:expand:media': 'default' | 'show_all' | 'hide_all' 8 | 'reading:expand:spoilers': boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/relationship.ts: -------------------------------------------------------------------------------- 1 | export type Relationship = { 2 | id: string 3 | following: boolean 4 | followed_by: boolean 5 | blocking: boolean 6 | blocked_by: boolean 7 | muting: boolean 8 | muting_notifications: boolean 9 | requested: boolean 10 | domain_blocking: boolean 11 | showing_reblogs: boolean 12 | endorsed: boolean 13 | notifying: boolean 14 | note: string 15 | languages: Array 16 | } 17 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/report.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | 3 | export type Report = { 4 | id: string 5 | action_taken: boolean 6 | action_taken_at: string | null 7 | category: Category 8 | comment: string 9 | forwarded: boolean 10 | status_ids: Array | null 11 | rule_ids: Array | null 12 | target_account: Account 13 | } 14 | 15 | export type Category = 'spam' | 'violation' | 'other' 16 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/results.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | import { Tag } from './tag.js' 4 | 5 | export type Results = { 6 | accounts: Array 7 | statuses: Array 8 | hashtags: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/scheduled_status.ts: -------------------------------------------------------------------------------- 1 | import { Attachment } from './attachment.js' 2 | import { StatusParams } from './status_params.js' 3 | 4 | export type ScheduledStatus = { 5 | id: string 6 | scheduled_at: string 7 | params: StatusParams 8 | media_attachments: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/source.ts: -------------------------------------------------------------------------------- 1 | import { Field } from './field.js' 2 | 3 | export type Source = { 4 | privacy: string | null 5 | sensitive: boolean | null 6 | language: string | null 7 | note: string 8 | fields: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/stats.ts: -------------------------------------------------------------------------------- 1 | export type Stats = { 2 | user_count: number 3 | status_count: number 4 | domain_count: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/status.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Application } from './application.js' 3 | import { Attachment } from './attachment.js' 4 | import { Mention } from './mention.js' 5 | import { Emoji } from './emoji.js' 6 | import { Poll } from './poll.js' 7 | 8 | export type Status = { 9 | id: string 10 | uri: string 11 | url: string 12 | account: Account 13 | in_reply_to_id: string | null 14 | in_reply_to_account_id: string | null 15 | reblog: Status | null 16 | content: string 17 | created_at: string 18 | edited_at: string | null 19 | emojis: Emoji[] 20 | replies_count: number 21 | reblogs_count: number 22 | favourites_count: number 23 | reblogged: boolean | null 24 | favourited: boolean | null 25 | muted: boolean | null 26 | sensitive: boolean 27 | spoiler_text: string 28 | visibility: StatusVisibility 29 | media_attachments: Array 30 | mentions: Array 31 | tags: Array 32 | poll: Poll | null 33 | application: Application | null 34 | language: string | null 35 | bookmarked?: boolean 36 | } 37 | 38 | export type StatusTag = { 39 | name: string 40 | url: string 41 | } 42 | 43 | export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct' 44 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/status_params.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type StatusParams = { 4 | text: string 5 | in_reply_to_id: string | null 6 | media_ids: Array | null 7 | sensitive: boolean | null 8 | spoiler_text: string | null 9 | visibility: StatusVisibility | null 10 | scheduled_at: string | null 11 | application_id: number 12 | } 13 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/tag.ts: -------------------------------------------------------------------------------- 1 | import { History } from './history.js' 2 | 3 | export type Tag = { 4 | name: string 5 | url: string 6 | history: Array 7 | following?: boolean 8 | } 9 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entities/token.ts: -------------------------------------------------------------------------------- 1 | export type Token = { 2 | access_token: string 3 | token_type: string 4 | scope: string 5 | created_at: number 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/entity.ts: -------------------------------------------------------------------------------- 1 | import * as account from './entities/account.js' 2 | import * as announcement from './entities/announcement.js' 3 | import * as application from './entities/application.js' 4 | import * as async_attachment from './entities/async_attachment.js' 5 | import * as attachment from './entities/attachment.js' 6 | import * as context from './entities/context.js' 7 | import * as conversation from './entities/conversation.js' 8 | import * as emoji from './entities/emoji.js' 9 | import * as field from './entities/field.js' 10 | import * as filter from './entities/filter.js' 11 | import * as history from './entities/history.js' 12 | import * as instance from './entities/instance.js' 13 | import * as marker from './entities/marker.js' 14 | import * as mentition from './entities/mention.js' 15 | import * as notification from './entities/notification.js' 16 | import * as poll from './entities/poll.js' 17 | import * as preferences from './entities/preferences.js' 18 | import * as relationship from './entities/relationship.js' 19 | import * as report from './entities/report.js' 20 | import * as results from './entities/results.js' 21 | import * as scheduled_status from './entities/scheduled_status.js' 22 | import * as source from './entities/source.js' 23 | import * as stats from './entities/stats.js' 24 | import * as status from './entities/status.js' 25 | import * as status_params from './entities/status_params.js' 26 | import * as tag from './entities/tag.js' 27 | import * as token from './entities/token.js' 28 | 29 | export namespace Entity { 30 | export type Account = account.Account 31 | export type Announcement = announcement.Announcement 32 | export type Application = application.Application 33 | export type AsyncAttachment = async_attachment.AsyncAttachment 34 | export type Attachment = attachment.Attachment 35 | export type Context = context.Context 36 | export type Conversation = conversation.Conversation 37 | export type Emoji = emoji.Emoji 38 | export type Field = field.Field 39 | export type Filter = filter.Filter 40 | export type FilterContext = filter.FilterContext 41 | export type History = history.History 42 | export type Instance = instance.Instance 43 | export type Marker = marker.Marker 44 | export type Mention = mentition.Mention 45 | export type Notification = notification.Notification 46 | export type NotificationType = notification.NotificationType 47 | export type Poll = poll.Poll 48 | export type PollOption = poll.PollOption 49 | export type Preferences = preferences.Preferences 50 | export type Relationship = relationship.Relationship 51 | export type Report = report.Report 52 | export type Results = results.Results 53 | export type ScheduledStatus = scheduled_status.ScheduledStatus 54 | export type Source = source.Source 55 | export type Stats = stats.Stats 56 | export type Status = status.Status 57 | export type StatusParams = status_params.StatusParams 58 | export type Tag = tag.Tag 59 | export type Token = token.Token 60 | } 61 | 62 | export default Entity 63 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/notification.ts: -------------------------------------------------------------------------------- 1 | import PixelfedEntity from './entity.js' 2 | 3 | namespace PixelfedNotificationType { 4 | export const Mention: PixelfedEntity.NotificationType = 'mention' 5 | export const Reblog: PixelfedEntity.NotificationType = 'reblog' 6 | export const Favourite: PixelfedEntity.NotificationType = 'favourite' 7 | export const Follow: PixelfedEntity.NotificationType = 'follow' 8 | export const FollowRequest: PixelfedEntity.NotificationType = 'follow_request' 9 | } 10 | 11 | export default PixelfedNotificationType 12 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/oauth.ts: -------------------------------------------------------------------------------- 1 | import OAuth from '@/oauth.js' 2 | 3 | export type AppDataFromServer = { 4 | id: string 5 | name: string 6 | website: string | null 7 | redirect_uri: string 8 | client_id: string 9 | client_secret: string 10 | } 11 | 12 | export type TokenDataFromServer = { 13 | access_token: string 14 | refresh_token: string 15 | token_type: string 16 | expires_in: number 17 | created_at: number 18 | } 19 | 20 | export function toAppData(appData: AppDataFromServer): OAuth.AppData { 21 | return { 22 | id: appData.id, 23 | name: appData.name, 24 | website: appData.website, 25 | redirect_uri: appData.redirect_uri, 26 | client_id: appData.client_id, 27 | client_secret: appData.client_secret, 28 | url: null, 29 | session_token: null 30 | } 31 | } 32 | 33 | export function toTokenData(tokenData: TokenDataFromServer): OAuth.TokenData { 34 | return { 35 | access_token: tokenData.access_token, 36 | token_type: tokenData.token_type, 37 | scope: '', 38 | created_at: tokenData.created_at, 39 | expires_in: tokenData.expires_in, 40 | refresh_token: tokenData.refresh_token 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /megalodon/src/pixelfed/web_socket.ts: -------------------------------------------------------------------------------- 1 | import { EventEmitter } from 'events' 2 | import { WebSocketInterface } from '../megalodon.js' 3 | 4 | /** 5 | * Streaming 6 | * Connect WebSocket streaming endpoint. 7 | */ 8 | export default class Streaming extends EventEmitter implements WebSocketInterface { 9 | constructor() { 10 | super() 11 | } 12 | 13 | /** 14 | * Start websocket connection. 15 | */ 16 | public start() {} 17 | 18 | /** 19 | * Stop current connection. 20 | */ 21 | public stop() {} 22 | } 23 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/account.ts: -------------------------------------------------------------------------------- 1 | import { Emoji } from './emoji.js' 2 | import { Field } from './field.js' 3 | import { Source } from './source.js' 4 | 5 | export type Account = { 6 | id: string 7 | username: string 8 | acct: string 9 | display_name: string 10 | locked: boolean 11 | discoverable?: boolean 12 | noindex: boolean | null 13 | suspended: boolean | null 14 | limited: boolean | null 15 | created_at: string 16 | followers_count: number 17 | following_count: number 18 | statuses_count: number 19 | note: string 20 | url: string 21 | avatar: string 22 | avatar_static: string 23 | header: string 24 | header_static: string 25 | emojis: Array 26 | moved: Account | null 27 | fields: Array 28 | bot: boolean 29 | source?: Source 30 | } 31 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/activity.ts: -------------------------------------------------------------------------------- 1 | export type Activity = { 2 | week: string 3 | statuses: string 4 | logins: string 5 | registrations: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/announcement.ts: -------------------------------------------------------------------------------- 1 | import { StatusTag } from './status.js' 2 | import { Emoji } from './emoji.js' 3 | 4 | export type Announcement = { 5 | id: string 6 | content: string 7 | starts_at: string | null 8 | ends_at: string | null 9 | published: boolean 10 | all_day: boolean 11 | published_at: string 12 | updated_at: string 13 | mentions: Array 14 | statuses: Array 15 | tags: Array 16 | emojis: Array 17 | reactions: Array 18 | } 19 | 20 | export type AnnouncementAccount = { 21 | id: string 22 | username: string 23 | url: string 24 | acct: string 25 | } 26 | 27 | export type AnnouncementStatus = { 28 | id: string 29 | url: string 30 | } 31 | 32 | export type AnnouncementReaction = { 33 | name: string 34 | count: number 35 | me: boolean | null 36 | url: string | null 37 | static_url: string | null 38 | } 39 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/application.ts: -------------------------------------------------------------------------------- 1 | export type Application = { 2 | name: string 3 | website?: string | null 4 | vapid_key?: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/async_attachment.ts: -------------------------------------------------------------------------------- 1 | import { Meta } from './attachment.js' 2 | 3 | export type AsyncAttachment = { 4 | id: string 5 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 6 | url: string | null 7 | remote_url: string | null 8 | preview_url: string 9 | text_url: string | null 10 | meta: Meta | null 11 | description: string | null 12 | blurhash: string | null 13 | } 14 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/attachment.ts: -------------------------------------------------------------------------------- 1 | export type Sub = { 2 | // For Image, Gifv, and Video 3 | width?: number 4 | height?: number 5 | size?: string 6 | aspect?: number 7 | 8 | // For Gifv and Video 9 | frame_rate?: string 10 | 11 | // For Audio, Gifv, and Video 12 | duration?: number 13 | bitrate?: number 14 | } 15 | 16 | export type Focus = { 17 | x: number 18 | y: number 19 | } 20 | 21 | export type Meta = { 22 | original?: Sub 23 | small?: Sub 24 | focus?: Focus 25 | length?: string 26 | duration?: number 27 | fps?: number 28 | size?: string 29 | width?: number 30 | height?: number 31 | aspect?: number 32 | audio_encode?: string 33 | audio_bitrate?: string 34 | audio_channel?: string 35 | } 36 | 37 | export type Attachment = { 38 | id: string 39 | type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' 40 | url: string 41 | remote_url: string | null 42 | preview_url: string | null 43 | text_url: string | null 44 | meta: Meta | null 45 | description: string | null 46 | blurhash: string | null 47 | } 48 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/card.ts: -------------------------------------------------------------------------------- 1 | export type Card = { 2 | url: string 3 | title: string 4 | description: string 5 | type: 'link' | 'photo' | 'video' | 'rich' 6 | image: string | null 7 | provider_name: string 8 | provider_url: string 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/context.ts: -------------------------------------------------------------------------------- 1 | import { Status } from './status.js' 2 | 3 | export type Context = { 4 | ancestors: Array 5 | descendants: Array 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/conversation.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | 4 | export type Conversation = { 5 | id: string 6 | accounts: Array 7 | last_status: Status | null 8 | unread: boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/emoji.ts: -------------------------------------------------------------------------------- 1 | export type Emoji = { 2 | shortcode: string 3 | static_url: string 4 | url: string 5 | visible_in_picker: boolean 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/featured_tag.ts: -------------------------------------------------------------------------------- 1 | export type FeaturedTag = { 2 | id: string 3 | name: string 4 | statuses_count: number 5 | last_status_at: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/field.ts: -------------------------------------------------------------------------------- 1 | export type Field = { 2 | name: string 3 | value: string 4 | verified_at: string | null 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/filter.ts: -------------------------------------------------------------------------------- 1 | export type Filter = { 2 | id: string 3 | phrase: string 4 | context: Array 5 | expires_at: string | null 6 | irreversible: boolean 7 | whole_word: boolean 8 | } 9 | 10 | export type FilterContext = string 11 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/history.ts: -------------------------------------------------------------------------------- 1 | export type History = { 2 | day: string 3 | uses: number 4 | accounts: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/identity_proof.ts: -------------------------------------------------------------------------------- 1 | export type IdentityProof = { 2 | provider: string 3 | provider_username: string 4 | updated_at: string 5 | proof_url: string 6 | profile_url: string 7 | } 8 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/instance.ts: -------------------------------------------------------------------------------- 1 | import { URLs } from './urls.js' 2 | import { Stats } from './stats.js' 3 | 4 | export type Instance = { 5 | uri: string 6 | title: string 7 | description: string 8 | email: string 9 | version: string 10 | thumbnail: string | null 11 | urls: URLs 12 | stats: Stats 13 | languages: Array 14 | registrations: boolean 15 | approval_required: boolean 16 | max_toot_chars: number 17 | max_media_attachments?: number 18 | pleroma: { 19 | metadata: { 20 | account_activation_required: boolean 21 | birthday_min_age: number 22 | birthday_required: boolean 23 | features: Array 24 | federation: { 25 | enabled: boolean 26 | exclusions: boolean 27 | } 28 | fields_limits: { 29 | max_fields: number 30 | max_remote_fields: number 31 | name_length: number 32 | value_length: number 33 | } 34 | post_formats: Array 35 | } 36 | } 37 | poll_limits: { 38 | max_expiration: number 39 | min_expiration: number 40 | max_option_chars: number 41 | max_options: number 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/list.ts: -------------------------------------------------------------------------------- 1 | export type List = { 2 | id: string 3 | title: string 4 | } 5 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/marker.ts: -------------------------------------------------------------------------------- 1 | export type Marker = { 2 | notifications: { 3 | last_read_id: string 4 | version: number 5 | updated_at: string 6 | pleroma: { 7 | unread_count: number 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/mention.ts: -------------------------------------------------------------------------------- 1 | export type Mention = { 2 | id: string 3 | username: string 4 | url: string 5 | acct: string 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/notification.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | 4 | export type Notification = { 5 | account: Account 6 | created_at: string 7 | id: string 8 | status?: Status 9 | emoji?: string 10 | emoji_url?: string 11 | type: NotificationType 12 | target?: Account 13 | } 14 | 15 | export type NotificationType = string 16 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/poll.ts: -------------------------------------------------------------------------------- 1 | export type Poll = { 2 | id: string 3 | expires_at: string | null 4 | expired: boolean 5 | multiple: boolean 6 | votes_count: number 7 | options: Array 8 | voted: boolean 9 | } 10 | 11 | export type PollOption = { 12 | title: string 13 | votes_count: number | null 14 | } 15 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/preferences.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type Preferences = { 4 | 'posting:default:visibility': StatusVisibility 5 | 'posting:default:sensitive': boolean 6 | 'posting:default:language': string | null 7 | 'reading:expand:media': 'default' | 'show_all' | 'hide_all' 8 | 'reading:expand:spoilers': boolean 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/push_subscription.ts: -------------------------------------------------------------------------------- 1 | export type Alerts = { 2 | follow: boolean 3 | favourite: boolean 4 | mention: boolean 5 | reblog: boolean 6 | poll: boolean 7 | } 8 | 9 | export type PushSubscription = { 10 | id: string 11 | endpoint: string 12 | server_key: string 13 | alerts: Alerts 14 | } 15 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/reaction.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | 3 | export type Reaction = { 4 | count: number 5 | me: boolean 6 | name: string 7 | accounts?: Array 8 | account_ids?: Array 9 | url?: string 10 | } 11 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/relationship.ts: -------------------------------------------------------------------------------- 1 | export type Relationship = { 2 | id: string 3 | following: boolean 4 | followed_by: boolean 5 | blocking: boolean 6 | blocked_by: boolean 7 | muting: boolean 8 | muting_notifications: boolean 9 | requested: boolean 10 | domain_blocking: boolean 11 | showing_reblogs: boolean 12 | endorsed: boolean 13 | subscribing: boolean 14 | notifying: boolean 15 | note: string 16 | } 17 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/report.ts: -------------------------------------------------------------------------------- 1 | export type Report = { 2 | id: string 3 | action_taken: boolean 4 | } 5 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/results.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Status } from './status.js' 3 | import { Tag } from './tag.js' 4 | 5 | export type Results = { 6 | accounts: Array 7 | statuses: Array 8 | hashtags: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/scheduled_status.ts: -------------------------------------------------------------------------------- 1 | import { Attachment } from './attachment.js' 2 | import { StatusParams } from './status_params.js' 3 | 4 | export type ScheduledStatus = { 5 | id: string 6 | scheduled_at: string 7 | params: StatusParams 8 | media_attachments: Array | null 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/source.ts: -------------------------------------------------------------------------------- 1 | import { Field } from './field.js' 2 | 3 | export type Source = { 4 | privacy: string | null 5 | sensitive: boolean | null 6 | language: string | null 7 | note: string 8 | fields: Array 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/stats.ts: -------------------------------------------------------------------------------- 1 | export type Stats = { 2 | user_count: number 3 | status_count: number 4 | domain_count: number 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/status.ts: -------------------------------------------------------------------------------- 1 | import { Account } from './account.js' 2 | import { Emoji } from './emoji.js' 3 | import { Application } from './application.js' 4 | import { Attachment } from './attachment.js' 5 | import { Mention } from './mention.js' 6 | import { Card } from './card.js' 7 | import { Reaction } from './reaction.js' 8 | import { Poll } from './poll.js' 9 | 10 | export type Status = { 11 | id: string 12 | uri: string 13 | url: string 14 | account: Account 15 | in_reply_to_id: string | null 16 | in_reply_to_account_id: string | null 17 | reblog: Status | null 18 | content: string 19 | created_at: string 20 | edited_at: string | null 21 | emojis: Emoji[] 22 | replies_count: number 23 | reblogs_count: number 24 | favourites_count: number 25 | reblogged: boolean | null 26 | favourited: boolean | null 27 | muted: boolean | null 28 | sensitive: boolean 29 | spoiler_text: string 30 | visibility: StatusVisibility 31 | media_attachments: Array 32 | mentions: Array 33 | tags: Array 34 | card: Card | null 35 | poll: Poll | null 36 | application: Application | null 37 | language: string | null 38 | pinned: boolean | null 39 | bookmarked?: boolean 40 | // Reblogged status contains only local parameter. 41 | pleroma: { 42 | content?: { 43 | 'text/plain': string 44 | } 45 | spoiler_text?: { 46 | 'text/plain': string 47 | } 48 | conversation_id?: number 49 | direct_conversation_id?: number | null 50 | emoji_reactions?: Array 51 | expires_at?: string 52 | in_reply_to_account_acct?: string 53 | local: boolean 54 | parent_visible?: boolean 55 | pinned_at?: string 56 | thread_muted?: boolean 57 | } 58 | } 59 | 60 | export type StatusTag = { 61 | name: string 62 | url: string 63 | } 64 | 65 | export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct' 66 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/status_params.ts: -------------------------------------------------------------------------------- 1 | import { StatusVisibility } from './status.js' 2 | 3 | export type StatusParams = { 4 | text: string 5 | in_reply_to_id: string | null 6 | media_ids?: Array | null 7 | sensitive: boolean | null 8 | spoiler_text: string | null 9 | visibility: StatusVisibility | null 10 | scheduled_at: string | null 11 | } 12 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/status_source.ts: -------------------------------------------------------------------------------- 1 | export type StatusSource = { 2 | id: string 3 | text: string 4 | spoiler_text: string 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/tag.ts: -------------------------------------------------------------------------------- 1 | import { History } from './history.js' 2 | 3 | export type Tag = { 4 | name: string 5 | url: string 6 | history: Array 7 | following?: boolean 8 | } 9 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/token.ts: -------------------------------------------------------------------------------- 1 | export type Token = { 2 | access_token: string 3 | token_type: string 4 | scope: string 5 | created_at: number 6 | } 7 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/entities/urls.ts: -------------------------------------------------------------------------------- 1 | export type URLs = { 2 | streaming_api: string 3 | } 4 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/notification.ts: -------------------------------------------------------------------------------- 1 | import PleromaEntity from './entity.js' 2 | 3 | namespace PleromaNotificationType { 4 | export const Mention: PleromaEntity.NotificationType = 'mention' 5 | export const Reblog: PleromaEntity.NotificationType = 'reblog' 6 | export const Favourite: PleromaEntity.NotificationType = 'favourite' 7 | export const Follow: PleromaEntity.NotificationType = 'follow' 8 | export const Poll: PleromaEntity.NotificationType = 'poll' 9 | export const PleromaEmojiReaction: PleromaEntity.NotificationType = 'pleroma:emoji_reaction' 10 | export const FollowRequest: PleromaEntity.NotificationType = 'follow_request' 11 | export const Update: PleromaEntity.NotificationType = 'update' 12 | export const Move: PleromaEntity.NotificationType = 'move' 13 | export const Status: PleromaEntity.NotificationType = 'status' 14 | } 15 | 16 | export default PleromaNotificationType 17 | -------------------------------------------------------------------------------- /megalodon/src/pleroma/oauth.ts: -------------------------------------------------------------------------------- 1 | import OAuth from '@/oauth.js' 2 | 3 | export type AppDataFromServer = { 4 | id: string 5 | name: string 6 | website: string | null 7 | redirect_uri: string 8 | client_id: string 9 | client_secret: string 10 | } 11 | 12 | export type TokenDataFromServer = { 13 | access_token: string 14 | token_type: string 15 | scope: string 16 | created_at: number 17 | expires_in: number | null 18 | refresh_token: string | null 19 | } 20 | 21 | export function toAppData(appData: AppDataFromServer): OAuth.AppData { 22 | return { 23 | id: appData.id, 24 | name: appData.name, 25 | website: appData.website, 26 | redirect_uri: appData.redirect_uri, 27 | client_id: appData.client_id, 28 | client_secret: appData.client_secret, 29 | url: null, 30 | session_token: null 31 | } 32 | } 33 | 34 | export function toTokenData(tokenData: TokenDataFromServer): OAuth.TokenData { 35 | return { 36 | access_token: tokenData.access_token, 37 | token_type: tokenData.token_type, 38 | scope: tokenData.scope, 39 | created_at: tokenData.created_at, 40 | expires_in: tokenData.expires_in, 41 | refresh_token: tokenData.refresh_token 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /megalodon/src/response.ts: -------------------------------------------------------------------------------- 1 | type Response = { 2 | data: T 3 | status: number 4 | statusText: string 5 | headers: any 6 | } 7 | 8 | export default Response 9 | -------------------------------------------------------------------------------- /megalodon/test/integration/cancel.spec.ts: -------------------------------------------------------------------------------- 1 | import MastodonAPI from '@/mastodon/api_client' 2 | import { Worker } from 'jest-worker' 3 | 4 | jest.mock('axios', () => { 5 | const mockAxios = jest.requireActual('axios') 6 | mockAxios.get = (_path: string) => { 7 | return new Promise(resolve => { 8 | setTimeout(() => { 9 | console.log('hoge') 10 | resolve({ 11 | data: 'hoge', 12 | status: 200, 13 | statusText: '200OK', 14 | headers: [], 15 | config: {} 16 | }) 17 | }, 5000) 18 | }) 19 | } 20 | return mockAxios 21 | }) 22 | 23 | const worker = async (client: MastodonAPI.Client) => { 24 | const w: any = new Worker(require.resolve('./cancelWorker.ts')) 25 | await w.cancel(client) 26 | } 27 | 28 | // Could not use jest-worker under typescript. 29 | // I'm waiting for resolve this issue. 30 | // https://github.com/facebook/jest/issues/8872 31 | describe.skip('cancel', () => { 32 | const client = new MastodonAPI.Client('testToken', 'https://pleroma.io/api/v1') 33 | it('should be raised', async () => { 34 | const getPromise = client.get<{}>('/timelines/home') 35 | worker(client) 36 | await expect(getPromise).rejects.toThrow() 37 | }) 38 | }) 39 | -------------------------------------------------------------------------------- /megalodon/test/integration/cancelWorker.ts: -------------------------------------------------------------------------------- 1 | import MastodonAPI from '@/mastodon/api_client' 2 | 3 | export function cancel(client: MastodonAPI.Client) { 4 | return client.cancel() 5 | } 6 | -------------------------------------------------------------------------------- /megalodon/test/integration/detector.spec.ts: -------------------------------------------------------------------------------- 1 | import { detector } from '../../src/index.js' 2 | 3 | describe('detector', () => { 4 | describe('mastodon', () => { 5 | const url = 'https://mastodon.social' 6 | it('should be mastodon', async () => { 7 | const mastodon = await detector(url) 8 | expect(mastodon).toEqual('mastodon') 9 | }) 10 | }) 11 | 12 | describe('pleroma', () => { 13 | const url = 'https://pleroma.io' 14 | it('should be pleroma', async () => { 15 | const pleroma = await detector(url) 16 | expect(pleroma).toEqual('pleroma') 17 | }) 18 | }) 19 | 20 | describe('fedibird', () => { 21 | const url = 'https://fedibird.com' 22 | it('should be mastodon', async () => { 23 | const fedibird = await detector(url) 24 | expect(fedibird).toEqual('mastodon') 25 | }, 20000) 26 | }) 27 | 28 | describe('friendica', () => { 29 | const url = 'https://squeet.me' 30 | it('should be friendica', async () => { 31 | const friendica = await detector(url) 32 | expect(friendica).toEqual('friendica') 33 | }) 34 | }) 35 | 36 | describe('akkoma', () => { 37 | const url = 'https://blob.cat' 38 | it('should be akkoma', async () => { 39 | const akkoma = await detector(url) 40 | expect(akkoma).toEqual('pleroma') 41 | }) 42 | }) 43 | 44 | describe('firefish', () => { 45 | const url = 'https://cybre.club' 46 | it('should be firefish', async () => { 47 | const firefish = await detector(url) 48 | expect(firefish).toEqual('firefish') 49 | }) 50 | }) 51 | 52 | describe('gotosocial', () => { 53 | const url = 'https://scg.owu.one' 54 | it('should be gotosocial', async () => { 55 | const gotosocial = await detector(url) 56 | expect(gotosocial).toEqual('gotosocial') 57 | }) 58 | }) 59 | 60 | describe('kmy.blue', () => { 61 | const url = 'https://kmy.blue' 62 | it('should be mastodon', async () => { 63 | const kmyblue = await detector(url) 64 | expect(kmyblue).toEqual('mastodon') 65 | }) 66 | }) 67 | 68 | describe('pixelfed.social', () => { 69 | const url = 'https://pixelfed.social' 70 | it('should be pixelfed', async () => { 71 | const pixelfed = await detector(url) 72 | expect(pixelfed).toEqual('pixelfed') 73 | }) 74 | }) 75 | 76 | describe('unknown', () => { 77 | const url = 'https://google.com' 78 | it('should be null', async () => { 79 | const unknown = detector(url) 80 | await expect(unknown).rejects.toThrow() 81 | }) 82 | }) 83 | }) 84 | -------------------------------------------------------------------------------- /megalodon/test/unit/mastodon.spec.ts: -------------------------------------------------------------------------------- 1 | describe('test', () => { 2 | it('should be true', () => { 3 | const res = true 4 | expect(res).toEqual(true) 5 | }) 6 | }) 7 | -------------------------------------------------------------------------------- /megalodon/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.esm.json", 3 | "compilerOptions": { 4 | "target": "es5", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "outDir": "./lib/cjs" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /megalodon/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.esm.json", 3 | "compilerOptions": { 4 | "types": ["node", "jest"] 5 | }, 6 | "include": ["./test", "../src"] 7 | } 8 | -------------------------------------------------------------------------------- /migration_guide.md: -------------------------------------------------------------------------------- 1 | # Upgrade v2.x to v3.0.0 2 | 3 | ## Overview 4 | `megalodon` start Misskey support in version 3.0.0. 5 | In this update, there are few breaking changes, so please read this migration guide if you are using megalodon v2.x. 6 | 7 | There are three changes, 8 | 9 | 1. Move class methods in Mastodon 10 | 2. I prepare methods to call each Mastodon APIs 11 | 3. Changed default export function 12 | 13 | 14 | 15 | ## Move class methods in Mastodon 16 | In [#180](https://github.com/h3poteto/megalodon/pull/180), these methods are moved and changed to instance methods: 17 | 18 | - `registerApp` 19 | - `createApp` 20 | - `generateAuthUrl` 21 | - `fetchAccessToken` 22 | - `refreshToken` 23 | 24 | So please call these methods from Mastodon like: 25 | 26 | ```typescript 27 | import { Mastodon } from 'megalodon' 28 | 29 | const client = new Mastodon(...) 30 | client.registerApp('TestApp') 31 | ``` 32 | 33 | ## I prepare methods to call each Mastodon APIs 34 | In v2.x, probably you use `megalodon` like: 35 | 36 | ```typescript 37 | import Mastodon from 'megalodon' 38 | 39 | const client = new Mastodon(...) 40 | 41 | client.get('/api/v1/timelines/home') 42 | 43 | ``` 44 | 45 | But these methods are deprecated, and are not exported from `megalodon` package. 46 | I prepared methods instead of these. 47 | 48 | There are all methods to call Mastodon APIs, so please use it. 49 | 50 | ```typescript 51 | import { Mastodon } from 'megalodon' 52 | 53 | const client = new Mastodon(...) 54 | 55 | client.getHomeTimeline() 56 | ``` 57 | 58 | Please refer `megalodon` [document](https://h3poteto.github.io/megalodon/) for methods. 59 | 60 | ## Changed default export function 61 | `megalodon` export `generator` function as default. 62 | This function generate Client API instance for specified SNS. 63 | 64 | ```typescript 65 | import generator from 'megalodon' 66 | 67 | const client = generator(sns_name, url, access_token) 68 | ``` 69 | 70 | Now support `mastodon`, `pleroma` and `misskey` as sns parameter. 71 | 72 | 73 | And detector function is defined. 74 | This function detect which SNS's URL is provided. 75 | It returns SNS name, `mastodon`, `pleroma` or `misskey`. 76 | 77 | ```typescript 78 | import { detector } from 'megalodon' 79 | 80 | const sns = await detector('https://mastodon.social') 81 | ``` 82 | 83 | These functions are necessary to treat multiple SNS. 84 | The smart way to call multiple SNS endpoint in same interface is: 85 | 86 | ```typescript 87 | import generator, { detector } from 'megalodon' 88 | 89 | const sns = await detector(url) 90 | const client = generator(sns, url, access_token) 91 | 92 | client.getHomeTimeline() 93 | ``` 94 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "workspaces": [ 4 | "megalodon", 5 | "example/node-cjs", 6 | "example/node-esm", 7 | "example/webpack", 8 | "example/vite" 9 | ], 10 | "packageManager": "yarn@4.6.0", 11 | "engines": { 12 | "npm": "use yarn instead", 13 | "yarn": "4.6.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:recommended" 5 | ], 6 | "rangeStrategy": "bump", 7 | "prConcurrentLimit": 20, 8 | "prHourlyLimit": 20 9 | } 10 | --------------------------------------------------------------------------------