Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ed710dc45a | |||
| 2efa5ec057 | |||
| 6e8a1018b3 | |||
| e16ab5b22f | |||
| f65b3d5e72 | |||
| fc325be4c7 | |||
| 87a424a6b7 | |||
| 331cff0550 | |||
| 714edfa147 | |||
| ab701005ec | |||
| 72d7616c16 | |||
| 0e3ce6a58a | |||
| 51a2acd8c3 | |||
| fb218bcbe1 | |||
| 4c508008b2 | |||
| 6371315b71 | |||
| 9ba65ee60a | |||
| d102adcebc | |||
| caa38f92e4 | |||
| 550018ed81 | |||
| e81dfba70a | |||
| 845dad288e | |||
| 84e10c529b | |||
| 85c8f8cc9f | |||
| 99387d1b3b | |||
| 8b2b1d2b13 | |||
| 59bfd58fba | |||
| 8c4dfeaa77 | |||
| e4338c80e7 | |||
| 004bfde9af | |||
| 895b693f81 | |||
| 336db2a5ca | |||
| f57ca58935 | |||
| f2c2007e07 | |||
| 47ead2151c | |||
| c2c9e6a8c1 | |||
| 2d1523de93 | |||
| 000dda7c4a | |||
| 714a3b852c |
@@ -1,48 +1,66 @@
|
||||
# Better uwuzu SDK
|
||||
[uwuzu.js](https://github.com/PutonFPS/uwuzu.js)みたいなやつです。uwuzuのAPIがいじれます。
|
||||
|
||||
# 使い方
|
||||
## インストール
|
||||
初期リリース出たら書きます
|
||||
|
||||
## 初期化
|
||||
```ts
|
||||
import uwuzu from "better-uwuzu-sdk";
|
||||
import type ApiMap from "better-uwuzu-sdk/1.6.11/map";
|
||||
|
||||
const client = new uwuzu<ApiMap>({
|
||||
origin: "https://uwuzu.net",
|
||||
});
|
||||
|
||||
try {
|
||||
client.token = "APITOKEN";
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
```
|
||||
型とJSDoc見ればわかります。トークンはなくても`serverinfo-api`や`token/get`は動きますが大体の事例では入れると思います。`uwuzu().token`の`set`は検証を行うわけではありませんが64文字でない、空文字列であるなどの場合はエラーが発生します。
|
||||
|
||||
## APIリクエスト
|
||||
```ts
|
||||
import uwuzu from "better-uwuzu-sdk";
|
||||
import type ApiMap from "better-uwuzu-sdk/1.6.11/map";
|
||||
|
||||
const client = new uwuzu<ApiMap>({
|
||||
origin: "https://uwuzu.net",
|
||||
});
|
||||
|
||||
try {
|
||||
client.token = "APITOKEN";
|
||||
|
||||
const me = await client.request("me/");
|
||||
|
||||
if (me.error_code) {
|
||||
throw new Error(me.error_code);
|
||||
}
|
||||
|
||||
console.log(`あなたは${me.username}です。`);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
```
|
||||
# Better uwuzu SDK
|
||||
[uwuzu.js](https://github.com/PutonFPS/uwuzu.js)みたいなやつです。uwuzuのAPIがいじれます。
|
||||
|
||||
# 使い方
|
||||
## インストール
|
||||
```bash
|
||||
# npm
|
||||
npm install git+https://gitea.last2014.com/last2014/better-uwuzu-sdk.git#1.1.6
|
||||
|
||||
# yarn
|
||||
yarn add git+https://gitea.last2014.com/last2014/better-uwuzu-sdk.git#1.1.6
|
||||
|
||||
# pnpm
|
||||
pnpm add git+https://gitea.last2014.com/last2014/better-uwuzu-sdk.git#1.1.6
|
||||
```
|
||||
> **NOTE**
|
||||
> このSDKはnpmリポジトリがありません。Gitリポジトリを使用しています。
|
||||
|
||||
> **WARNING**
|
||||
> `#main`でのインストールもできますが破壊的変更の際に面倒だと思います。サポートしません。
|
||||
|
||||
## 初期化
|
||||
```ts
|
||||
import uwuzu from "better-uwuzu-sdk";
|
||||
import type ApiMap from "better-uwuzu-sdk/1.6.8/map";
|
||||
import Parser from "better-uwuzu-sdk/1.6.8/parser";
|
||||
|
||||
const client = new uwuzu<ApiMap>({
|
||||
origin: "https://uwuzu.net",
|
||||
parser: Parser,
|
||||
});
|
||||
|
||||
try {
|
||||
client.token = "APITOKEN";
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
```
|
||||
型とJSDoc見ればわかります。トークンはなくても`serverinfo-api`や`token/get`は動きますが大体の事例では入れると思います。`uwuzu().token`の`set`は検証を行うわけではありませんが64文字でない、空文字列であるなどの場合はエラーが発生します。
|
||||
|
||||
## APIリクエスト
|
||||
```ts
|
||||
import uwuzu from "better-uwuzu-sdk";
|
||||
import type ApiMap from "better-uwuzu-sdk/1.6.8/map";
|
||||
import Parser from "better-uwuzu-sdk/1.6.8/parser";
|
||||
|
||||
const client = new uwuzu<ApiMap>({
|
||||
origin: "https://uwuzu.net",
|
||||
parser: Parser,
|
||||
});
|
||||
|
||||
try {
|
||||
client.token = "APITOKEN";
|
||||
|
||||
const me = await client.request("me/");
|
||||
|
||||
if (me.error_code) {
|
||||
throw new Error(me.error_code);
|
||||
}
|
||||
|
||||
console.log(`あなたは${me.username}です。`);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
```
|
||||
普通のSDKです。`uwuzu().request()`の第一引数はエンドポイント、第二引数はbodyです。bodyにトークンは自動入力されるので上記の例のように省略できます。
|
||||
+30
-7
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "better-uwuzu-sdk",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.6",
|
||||
"description": "A better uwuzu SDK.",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/types/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc && tsc-alias",
|
||||
"prepare": "tsc && tsc-alias"
|
||||
"build": "tsc && tsc-alias && cpx \"src/**/*.d.ts\" dist/types",
|
||||
"prepare": "tsc && tsc-alias && cpx \"src/**/*.d.ts\" dist/types"
|
||||
},
|
||||
"keywords": [
|
||||
"uwuzu",
|
||||
@@ -23,16 +23,39 @@
|
||||
"email": "info@last2014.com",
|
||||
"url": "https://about.last2014.com"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"types": "./dist/types/index.d.ts"
|
||||
},
|
||||
"./*": {
|
||||
"import": "./dist/*.js",
|
||||
"types": "./dist/types/*.d.ts"
|
||||
},
|
||||
"./*/*": {
|
||||
"import": "./dist/*/*.js",
|
||||
"types": "./dist/types/*/*.d.ts"
|
||||
},
|
||||
"./*/*/*": {
|
||||
"import": "./dist/*/*/*.js",
|
||||
"types": "./dist/types/*/*/*.d.ts"
|
||||
},
|
||||
"./*/*/*/*": {
|
||||
"import": "./dist/*/*/*/*.js",
|
||||
"types": "./dist/types/*/*/*/*.d.ts"
|
||||
},
|
||||
"./*/*/*/*/*": {
|
||||
"import": "./dist/*/*/*/*/*.js",
|
||||
"types": "./dist/types/*/*/*/*/*.d.ts"
|
||||
}
|
||||
},
|
||||
"license": "MIT",
|
||||
"packageManager": "pnpm@10.17.0",
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.0.3",
|
||||
"fs": "0.0.1-security",
|
||||
"cpx": "^1.5.0",
|
||||
"tsc-alias": "^1.8.16",
|
||||
"typescript": "^5.9.3",
|
||||
"uuid": "^13.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/semver": "^7.7.1"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+1252
-13
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
onlyBuiltDependencies:
|
||||
- core-js
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { generateAuthURIOptions } from "1.6.8/types/auth";
|
||||
import type { generateAuthURIOptions } from "./types/auth";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
/** ユーザー認可によるトークン取得のURIを生成します。 */
|
||||
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import { ApiMap } from "./types/api/map";
|
||||
export default ApiMap;
|
||||
@@ -1,2 +0,0 @@
|
||||
import { ApiMap } from "1.6.8/types/api/map";
|
||||
export default ApiMap;
|
||||
@@ -0,0 +1,89 @@
|
||||
import type { parserType } from "../index";
|
||||
|
||||
const mediaToObj = (ueuse: any) => {
|
||||
const media = {
|
||||
photo: [] as string[],
|
||||
video: [] as string[],
|
||||
};
|
||||
|
||||
if (ueuse.photo1 !== "" || ueuse.video1 !== "") {
|
||||
if (ueuse.photo1 !== "") {
|
||||
media.photo.push(ueuse.photo1);
|
||||
delete ueuse.photo1;
|
||||
}
|
||||
if (ueuse.photo2 !== "") {
|
||||
media.photo.push(ueuse.photo2);
|
||||
delete ueuse.photo2;
|
||||
}
|
||||
if (ueuse.photo3 !== "") {
|
||||
media.photo.push(ueuse.photo3);
|
||||
delete ueuse.photo3;
|
||||
}
|
||||
if (ueuse.photo4 !== "") {
|
||||
media.photo.push(ueuse.photo4);
|
||||
delete ueuse.photo4;
|
||||
}
|
||||
if (ueuse.video1 !== "") {
|
||||
media.video.push(ueuse.video1);
|
||||
delete ueuse.video1;
|
||||
}
|
||||
}
|
||||
|
||||
ueuse.media = media;
|
||||
|
||||
return ueuse;
|
||||
}
|
||||
|
||||
const Parser: parserType = (data, type, endpoint) => {
|
||||
let result = data;
|
||||
|
||||
if (type === "request") {
|
||||
if (result.media && result.text && endpoint === "ueuse/create") {
|
||||
if (result.media.photo) {
|
||||
for (let i = 0; i < result.media.photo.length; i++) {
|
||||
result[`photo${i + 1}`] = result.media.photo[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (result.media.video) {
|
||||
for (let i = 0; i < result.media.video.length; i++) {
|
||||
result[`video${i + 1}`] = result.media.video[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} else {
|
||||
if (result["0"] !== undefined && result.success === true) {
|
||||
delete result.success;
|
||||
|
||||
const objData: any[] = Object.values(result);
|
||||
|
||||
for (let i = 0; i < objData.length; i++) {
|
||||
if (endpoint.indexOf("ueuse") !== -1) {
|
||||
objData[i] = mediaToObj(objData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: objData,
|
||||
};
|
||||
}
|
||||
|
||||
if (result.favorite_list !== undefined && result.success === true) {
|
||||
delete result.success;
|
||||
|
||||
const list = result.favorite_list.split(",");
|
||||
|
||||
return {
|
||||
success: true,
|
||||
favorite_list: list,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export default Parser;
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import Page from "1.6.8/types/modules/page";
|
||||
import InputError from "../../../modules/error/input";
|
||||
import AuthError from "../../../modules/error/auth";
|
||||
import Page from "../../../modules/page";
|
||||
|
||||
export default interface AdminReports {
|
||||
"admin/reports/": {
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import InputError from "../../../modules/error/input";
|
||||
import AuthError from "../../../modules/error/auth";
|
||||
|
||||
export default interface AdminReportsResolve {
|
||||
"admin/reports/resolve": {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { UserResponse } from "1.6.8/types/api/users";
|
||||
import { UserResponse } from "../../../api/users";
|
||||
|
||||
export default interface AdminUsers {
|
||||
"admin/users/": {
|
||||
Vendored
+3
-3
@@ -1,6 +1,6 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import { UserDataNotFound } from "1.6.8/types/modules/error/critical";
|
||||
import InputError from "../../../modules/error/input";
|
||||
import AuthError from "../../../modules/error/auth";
|
||||
import { UserDataNotFound } from "../../../modules/error/critical";
|
||||
|
||||
interface RequestBase<T extends string> {
|
||||
/** 対象のユーザーID */
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
|
||||
export default interface FavoriteChange {
|
||||
"favorite/change": {
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
|
||||
export default interface FavoriteGet {
|
||||
"favorite/get": {
|
||||
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
import ServerInfo from "./serverinfo-api";
|
||||
import Users from "./users";
|
||||
import UsersFollow from "./users/follow";
|
||||
import Me from "./me";
|
||||
import MeNotification from "./me/notification";
|
||||
import MeNotificationRead from "./me/notification/read";
|
||||
import MeSettings from "./me/settings";
|
||||
import Ueuse from "./ueuse";
|
||||
import UeuseGet from "./ueuse/get";
|
||||
import UeuseReplies from "./ueuse/replies";
|
||||
import UeuseMentions from "./ueuse/mentions";
|
||||
import UeuseSearch from "./ueuse/search";
|
||||
import UeuseCreate from "./ueuse/create";
|
||||
import UeuseDelete from "./ueuse/delete";
|
||||
import UeuseBookmark from "./ueuse/bookmark";
|
||||
import FavoriteChange from "./favorite/change";
|
||||
import FavoriteGet from "./favorite/get";
|
||||
import TokenGet from "./token/get";
|
||||
import AdminUsers from "./admin/users";
|
||||
import AdminUsersSanction from "./admin/users/sanction";
|
||||
import AdminReports from "./admin/reports";
|
||||
import AdminReportsResolve from "./admin/reports/resolve";
|
||||
|
||||
export type ApiMap =
|
||||
& ServerInfo
|
||||
& Me
|
||||
& MeNotification
|
||||
& MeNotificationRead
|
||||
& MeSettings
|
||||
& Users
|
||||
& UsersFollow
|
||||
& Ueuse
|
||||
& UeuseGet
|
||||
& UeuseReplies
|
||||
& UeuseMentions
|
||||
& UeuseSearch
|
||||
& UeuseCreate
|
||||
& UeuseDelete<string>
|
||||
& UeuseBookmark
|
||||
& FavoriteChange
|
||||
& FavoriteGet
|
||||
& TokenGet
|
||||
& AdminUsers
|
||||
& AdminUsersSanction<string>
|
||||
& AdminReports
|
||||
& AdminReportsResolve;
|
||||
@@ -1,18 +0,0 @@
|
||||
import ServerInfo from "1.6.8/types/api/serverinfo-api";
|
||||
import Users from "1.6.8/types/api/users";
|
||||
import UsersFollow from "1.6.8/types/api/users/follow";
|
||||
import Me from "1.6.8/types/api/me";
|
||||
import MeNotification from "1.6.8/types/api/me/notification";
|
||||
import MeNotificationRead from "1.6.8/types/api/me/notification/read";
|
||||
import MeSettings from "1.6.8/types/api/me/settings";
|
||||
import Ueuse from "1.6.8/types/api/ueuse";
|
||||
|
||||
export type ApiMap =
|
||||
& ServerInfo
|
||||
& Me
|
||||
& MeNotification
|
||||
& MeNotificationRead
|
||||
& MeSettings
|
||||
& Users
|
||||
& UsersFollow
|
||||
& Ueuse;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UserResponse } from "1.6.8/types/api/users";
|
||||
import { UserResponse } from "../../api/users";
|
||||
|
||||
export default interface Me {
|
||||
"me/": {
|
||||
Vendored
+3
-3
@@ -1,6 +1,6 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import Page from "1.6.8/types/modules/page";
|
||||
import InputError from "../../../modules/error/input";
|
||||
import AuthError from "../../../modules/error/auth";
|
||||
import Page from "../../../modules/page";
|
||||
|
||||
export default interface MeNotification {
|
||||
"me/notification/": {
|
||||
Vendored
+3
-3
@@ -1,6 +1,6 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import UpdateError from "1.6.8/types/modules/error/update";
|
||||
import InputError from "../../../modules/error/input";
|
||||
import AuthError from "../../../modules/error/auth";
|
||||
import UpdateError from "../../../modules/error/update";
|
||||
|
||||
export default interface MeNotificationRead {
|
||||
"me/notification/read": {
|
||||
@@ -1,7 +1,7 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import UpdateError from "1.6.8/types/modules/error/update";
|
||||
import { Upload1Error, Upload2Error, UploadCommonError } from "1.6.8/types/modules/error/upload";
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
import UpdateError from "../../modules/error/update";
|
||||
import { Upload1Error, Upload2Error, UploadCommonError } from "../../modules/error/upload";
|
||||
|
||||
type AtLeastOne<T> = {
|
||||
[K in keyof T]: Required<Pick<T, K>> & Partial<Omit<T, K>>
|
||||
@@ -1,8 +1,8 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import { UserDataNotFound } from "1.6.8/types/modules/error/critical";
|
||||
import InputError from "../../modules/error/input";
|
||||
import { UserDataNotFound } from "../../modules/error/critical";
|
||||
|
||||
export default interface TokenGet {
|
||||
"ueuse/get": {
|
||||
"token/get": {
|
||||
body: {
|
||||
/** api/authで使用したセッション */
|
||||
session: string;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import InputError from "../../../modules/error/input";
|
||||
import AuthError from "../../../modules/error/auth";
|
||||
import ueuseModule from "../../../modules/ueuse";
|
||||
import ueuseError from "../../../modules/error/ueuse";
|
||||
import Page from "../../../modules/page";
|
||||
|
||||
export default interface UeuseBookmark {
|
||||
"ueuse/bookmark/": {
|
||||
body?: Page;
|
||||
response: {
|
||||
/** 成功かどうか */
|
||||
success: true;
|
||||
/** ブックマークしているユーズ */
|
||||
data: ueuseModule[];
|
||||
} | InputError | AuthError | ueuseError;
|
||||
}
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import { ueuseModule } from "1.6.8/types/modules/ueuse";
|
||||
import ueuseError from "1.6.8/types/modules/error/ueuse";
|
||||
import Page from "1.6.8/types/modules/page";
|
||||
|
||||
export default interface UeuseBookmark {
|
||||
"ueuse/bookmark/": {
|
||||
body?: Page;
|
||||
response: {
|
||||
/** 成功かどうか */
|
||||
success: true;
|
||||
/** ブックマークしているユーズ */
|
||||
data: ueuseModule[];
|
||||
} | InputError | AuthError | ueuseError;
|
||||
}
|
||||
};
|
||||
+6
-4
@@ -1,12 +1,14 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import { Media } from "1.6.8/types/modules/ueuse";
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
import { Media } from "../../modules/ueuse";
|
||||
|
||||
export default interface UeuseCreate {
|
||||
"ueuse/get": {
|
||||
"ueuse/create": {
|
||||
body: {
|
||||
/** 本文 */
|
||||
text: string;
|
||||
/** メディア */
|
||||
media: Media;
|
||||
/** NSFWにするかどうか */
|
||||
nsfw?: boolean;
|
||||
/** 返信先ユーズのユニークID */
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
|
||||
interface ResponseBase<T extends string, S extends boolean> {
|
||||
/** 成功かどうか */
|
||||
@@ -1,7 +1,7 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import { ueuseModule } from "1.6.8/types/modules/ueuse";
|
||||
import ueuseError from "1.6.8/types/modules/error/ueuse";
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
import ueuseModule from "../../modules/ueuse";
|
||||
import ueuseError from "../../modules/error/ueuse";
|
||||
|
||||
export default interface UeuseGet {
|
||||
"ueuse/get": {
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
import ueuseModule from "../../modules/ueuse";
|
||||
import ueuseError from "../../modules/error/ueuse";
|
||||
import Page from "../../modules/page";
|
||||
|
||||
export default interface Ueuse {
|
||||
"ueuse/": {
|
||||
body?: Page;
|
||||
response: {
|
||||
/** 成功かどうか */
|
||||
success: true;
|
||||
/** ユーズ(LTL) */
|
||||
data: ueuseModule[];
|
||||
} | InputError | AuthError | ueuseError;
|
||||
}
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import { ueuseModule } from "1.6.8/types/modules/ueuse";
|
||||
import ueuseError from "1.6.8/types/modules/error/ueuse";
|
||||
import Page from "1.6.8/types/modules/page";
|
||||
|
||||
export default interface Ueuse {
|
||||
"ueuse/": {
|
||||
body?: Page;
|
||||
response: {
|
||||
/** 成功かどうか */
|
||||
success: true;
|
||||
/** ユーズ(LTL) */
|
||||
data: ueuseModule[];
|
||||
} | InputError | AuthError | ueuseError;
|
||||
}
|
||||
};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
import ueuseModule from "../../modules/ueuse";
|
||||
import ueuseError from "../../modules/error/ueuse";
|
||||
import Page from "../../modules/page";
|
||||
|
||||
export default interface UeuseMentions {
|
||||
"ueuse/mentions": {
|
||||
body?: Page;
|
||||
response: {
|
||||
/** 成功かどうか */
|
||||
success: true;
|
||||
/** メンションされているユーズ */
|
||||
data: ueuseModule[];
|
||||
} | InputError | AuthError | ueuseError;
|
||||
}
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import { ueuseModule } from "1.6.8/types/modules/ueuse";
|
||||
import ueuseError from "1.6.8/types/modules/error/ueuse";
|
||||
import Page from "1.6.8/types/modules/page";
|
||||
|
||||
export default interface UeuseMentions {
|
||||
"ueuse/mentions": {
|
||||
body?: Page;
|
||||
response: {
|
||||
/** 成功かどうか */
|
||||
success: true;
|
||||
/** メンションされているユーズ */
|
||||
data: ueuseModule[];
|
||||
} | InputError | AuthError | ueuseError;
|
||||
}
|
||||
};
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import { ueuseModule } from "1.6.8/types/modules/ueuse";
|
||||
import ueuseError from "1.6.8/types/modules/error/ueuse";
|
||||
import Page from "1.6.8/types/modules/page";
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
import ueuseModule from "../../modules/ueuse";
|
||||
import ueuseError from "../../modules/error/ueuse";
|
||||
import Page from "../../modules/page";
|
||||
|
||||
export default interface UeuseReplies {
|
||||
"ueuse/replies": {
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import { ueuseModule } from "1.6.8/types/modules/ueuse";
|
||||
import ueuseError from "1.6.8/types/modules/error/ueuse";
|
||||
import Page from "1.6.8/types/modules/page";
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
import ueuseModule from "../../modules/ueuse";
|
||||
import ueuseError from "../../modules/error/ueuse";
|
||||
import Page from "../../modules/page";
|
||||
|
||||
export default interface UeuseSearch {
|
||||
"ueuse/search": {
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import UpdateError, { CouldNotComplete } from "1.6.8/types/modules/error/update";
|
||||
import ToYouNotAllowed from "1.6.8/types/modules/error/follow";
|
||||
import { UserDataNotFound } from "1.6.8/types/modules/error/critical";
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
import UpdateError, { CouldNotComplete } from "../../modules/error/update";
|
||||
import ToYouNotAllowed from "../../modules/error/follow";
|
||||
import { UserDataNotFound } from "../../modules/error/critical";
|
||||
|
||||
interface Follow<T extends string> {
|
||||
body: {
|
||||
@@ -1,7 +1,7 @@
|
||||
import Role from "1.6.8/types/modules/role";
|
||||
import InputError from "1.6.8/types/modules/error/input";
|
||||
import AuthError from "1.6.8/types/modules/error/auth";
|
||||
import { UserDataNotFound } from "1.6.8/types/modules/error/critical";
|
||||
import Role from "../../modules/role";
|
||||
import InputError from "../../modules/error/input";
|
||||
import AuthError from "../../modules/error/auth";
|
||||
import { UserDataNotFound } from "../../modules/error/critical";
|
||||
|
||||
export type UserResponse = {
|
||||
/** 成功かどうか */
|
||||
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
export interface Media {
|
||||
/** 画像URL */
|
||||
photo: string[];
|
||||
/** 動画URL */
|
||||
video: string[];
|
||||
};
|
||||
|
||||
export default interface ueuseModule {
|
||||
/** ユニークID */
|
||||
uniqid: string;
|
||||
/**
|
||||
* 返信先ID
|
||||
* 返信でない場合は空文字列です。
|
||||
*/
|
||||
replyid: string | "";
|
||||
/**
|
||||
* リユーズ/引用元ID
|
||||
* リユーズ/引用でない場合は空文字列です。
|
||||
*/
|
||||
reuseid: string | "";
|
||||
/** 送信者 */
|
||||
account: {
|
||||
/** ユーザー名 */
|
||||
username: string;
|
||||
/** ユーザーID */
|
||||
userid: string;
|
||||
/** ユーザーアイコン画像URL */
|
||||
user_icon: string;
|
||||
/** ユーザーヘッダー画像URL */
|
||||
user_header: string;
|
||||
/** Botフラグ(自主設定)かどうか */
|
||||
is_bot: boolean;
|
||||
};
|
||||
/** 本文 */
|
||||
text: string;
|
||||
/** いいねしたユーザーID */
|
||||
favorite: string[];
|
||||
/** メディア */
|
||||
media: Media;
|
||||
/** いいね数 */
|
||||
favorite_cnt: number;
|
||||
/** 返信数 */
|
||||
reply_cnt: number;
|
||||
/** リユーズ+引用数 */
|
||||
reuse_cnt: number;
|
||||
/**
|
||||
* 送信時刻
|
||||
* YYYY-MM-DD HH:MM:SS形式です。
|
||||
*/
|
||||
datetime: string;
|
||||
/**
|
||||
* 追記
|
||||
* 追記がない場合は空文字列です。
|
||||
*/
|
||||
abi: string | "";
|
||||
/**
|
||||
* 追記時刻
|
||||
* 追記がない場合は0000-00-00 00:00:00です。
|
||||
* YYYY-MM-DD HH:MM:SS形式です。
|
||||
*/
|
||||
abidatetime: string | "0000-00-00 00:00:00";
|
||||
/** NSFW(自主設定)かどうか */
|
||||
nsfw: boolean;
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
type Abi = {
|
||||
/**
|
||||
* 追記
|
||||
* 追記がない場合は空文字列です。
|
||||
*/
|
||||
abi: string;
|
||||
/** 追記時刻 */
|
||||
abidatetime: string;
|
||||
} | {
|
||||
/**
|
||||
* 追記
|
||||
* 追記が入力できないため常に空文字列です。
|
||||
*/
|
||||
abi: "";
|
||||
/**
|
||||
* 追記時刻
|
||||
* 追記が入力できないため常に0000-00-00 00:00:00です。
|
||||
*/
|
||||
abidatetime: "0000-00-00 00:00:00";
|
||||
}
|
||||
|
||||
export type Media =
|
||||
| {
|
||||
/**
|
||||
* 画像1URL
|
||||
* 画像1がないため常に空文字列です。
|
||||
*/
|
||||
photo1?: undefined;
|
||||
/**
|
||||
* 画像2URL
|
||||
* 画像2がないため常に空文字列です。
|
||||
* 画像2は画像1が入力されていることの内包条件です。
|
||||
*/
|
||||
photo2?: undefined;
|
||||
/**
|
||||
* 画像3URL
|
||||
* 画像3がないため常に空文字列です。
|
||||
* 画像3は画像2が入力されていることの内包条件です。
|
||||
*/
|
||||
photo3?: undefined;
|
||||
/**
|
||||
* 画像4URL
|
||||
* 画像4がないため常に空文字列です。
|
||||
* 画像4は画像3が入力されていることの内包条件です。
|
||||
*/
|
||||
photo4?: undefined;
|
||||
/**
|
||||
* 動画URL
|
||||
* 動画がないため常に空文字列です。
|
||||
*/
|
||||
video1?: undefined;
|
||||
} | {
|
||||
/** 画像1URL */
|
||||
photo1: string;
|
||||
/**
|
||||
* 画像2URL
|
||||
* 画像2がない場合は空文字列です。
|
||||
* 画像2は画像1が入力されていることの内包条件です。
|
||||
*/
|
||||
photo2?: string;
|
||||
/**
|
||||
* 画像3URL
|
||||
* 画像3がない場合は空文字列です。
|
||||
* 画像3は画像2が入力されていることの内包条件です。
|
||||
*/
|
||||
photo3?: string;
|
||||
/**
|
||||
* 画像4URL
|
||||
* 画像4がない場合は空文字列です。
|
||||
* 画像4は画像3が入力されていることの内包条件です。
|
||||
*/
|
||||
photo4?: string;
|
||||
/**
|
||||
* 動画URL
|
||||
* 動画がないため常に空文字列です。
|
||||
*/
|
||||
video1?: undefined;
|
||||
} | {
|
||||
/** 動画URL */
|
||||
video1: string;
|
||||
/**
|
||||
* 画像1URL
|
||||
* 画像1がないため常に空文字列です。
|
||||
*/
|
||||
photo1?: undefined;
|
||||
/**
|
||||
* 画像2URL
|
||||
* 画像2がないため常に空文字列です。
|
||||
* 画像2は画像1が入力されていることの内包条件です。
|
||||
*/
|
||||
photo2?: undefined;
|
||||
/**
|
||||
* 画像3URL
|
||||
* 画像3がないため常に空文字列です。
|
||||
* 画像3は画像1が入力されていることの内包条件です。
|
||||
*/
|
||||
photo3?: undefined;
|
||||
/**
|
||||
* 画像4URL
|
||||
* 画像4がないため常に空文字列です。
|
||||
* 画像4は画像1が入力されていることの内包条件です。
|
||||
*/
|
||||
photo4?: undefined;
|
||||
};
|
||||
|
||||
interface ueuseBase {
|
||||
/** ユニークID */
|
||||
uniqid: string;
|
||||
/** 送信者 */
|
||||
account: {
|
||||
/** ユーザー名 */
|
||||
username: string;
|
||||
/** ユーザーID */
|
||||
userid: string;
|
||||
/** ユーザーアイコン画像URL */
|
||||
user_icon: string;
|
||||
/** ユーザーヘッダー画像URL */
|
||||
user_header: string;
|
||||
/** Botフラグ(自主設定)かどうか */
|
||||
is_bot: boolean;
|
||||
};
|
||||
/** いいねしたユーザーID */
|
||||
favorite: string[];
|
||||
/** いいね数 */
|
||||
favorite_cnt: number;
|
||||
/** 返信数 */
|
||||
reply_cnt: number;
|
||||
/** リユーズ+引用数 */
|
||||
reuse_cnt: number;
|
||||
/** 送信時刻 */
|
||||
datetime: string;
|
||||
/** NSFW(自主設定)かどうか */
|
||||
nsfw: boolean;
|
||||
}
|
||||
|
||||
interface NormalUeuse extends ueuseBase {
|
||||
/** 本文 */
|
||||
text: string;
|
||||
/**
|
||||
* 返信先ID
|
||||
* 返信でないため空文字列です。
|
||||
*/
|
||||
replyid: "";
|
||||
/**
|
||||
* リユーズ/引用元ID
|
||||
* リユーズ/引用でないため空文字列です。
|
||||
*/
|
||||
reuseid: "";
|
||||
}
|
||||
|
||||
interface ReplyUeuse extends ueuseBase {
|
||||
/** 本文 */
|
||||
text: string;
|
||||
/** 返信先ID */
|
||||
replyid: string;
|
||||
/**
|
||||
* リユーズ/引用元ID
|
||||
* リユーズ/引用でないため空文字列です。
|
||||
*/
|
||||
reuseid: "";
|
||||
}
|
||||
|
||||
interface Reuse extends ueuseBase {
|
||||
/**
|
||||
* 本文
|
||||
* リユーズであるため常に空文字列です。
|
||||
*/
|
||||
text: "";
|
||||
/**
|
||||
* 返信先ID
|
||||
* 返信でないため空文字列です。
|
||||
*/
|
||||
replyid: "";
|
||||
/** リユーズ/引用元ID */
|
||||
reuseid: string;
|
||||
/**
|
||||
* 追記
|
||||
* リユーズであるため常に空文字列です。
|
||||
*/
|
||||
abi: "";
|
||||
/**
|
||||
* 追記時刻
|
||||
* リユーズであるため常に0000-00-00 00:00:00です。
|
||||
*/
|
||||
abidatetime: "0000-00-00 00:00:00";
|
||||
}
|
||||
|
||||
interface QuoteReuse extends ueuseBase {
|
||||
/** 本文 */
|
||||
text: string;
|
||||
/**
|
||||
* 返信先ID
|
||||
* 返信でないため空文字列です。
|
||||
*/
|
||||
replyid: "";
|
||||
/** 引用元ID */
|
||||
reuseid: string;
|
||||
}
|
||||
|
||||
type Ext = Abi & Media;
|
||||
|
||||
export type ueuseModule =
|
||||
| (NormalUeuse & Ext)
|
||||
| (ReplyUeuse & Ext)
|
||||
| (QuoteReuse & Ext)
|
||||
| Reuse;
|
||||
+23
-29
@@ -1,9 +1,19 @@
|
||||
import uwuzuError from "@/lib/error";
|
||||
import uwuzuFetch from "@/lib/fetch";
|
||||
import uwuzuError from "./lib/error";
|
||||
import uwuzuFetch from "./lib/fetch";
|
||||
|
||||
export type parserType = (
|
||||
data: any,
|
||||
type: "request" | "response",
|
||||
endpoint: string,
|
||||
) => any;
|
||||
|
||||
interface sdkOptions {
|
||||
/** uwuzuサーバーのorigin */
|
||||
origin: string;
|
||||
/**
|
||||
* リクエスト/レスポンスのパーサー
|
||||
*/
|
||||
parser: parserType;
|
||||
/**
|
||||
* 通信に失敗した際の再試行回数です。
|
||||
* 全て失敗した場合はエラーを発生します。
|
||||
@@ -29,15 +39,18 @@ export default class uwuzu<
|
||||
M extends { [K in keyof M]: { body?: any; response: any } }
|
||||
> {
|
||||
readonly origin: string;
|
||||
readonly parser: parserType;
|
||||
readonly retry: number;
|
||||
readonly waiting: number;
|
||||
private _token: string | null = null;
|
||||
|
||||
constructor(options: sdkOptions) {
|
||||
this.origin = options.origin;
|
||||
this.parser = options.parser;
|
||||
this.retry = options.retry ?? 5;
|
||||
this.waiting = options.waiting ?? 500;
|
||||
|
||||
if (!this.parser) throw new uwuzuError("Invalid parser.");
|
||||
if (this.retry < 1) throw new uwuzuError("Invalid retry count.");
|
||||
if (this.waiting < 1) throw new uwuzuError("Invalid base waiting time.");
|
||||
if (options.origin !== new URL(options.origin).origin)
|
||||
@@ -73,10 +86,16 @@ export default class uwuzu<
|
||||
let bodyParsed: any = args[0] ?? {};
|
||||
|
||||
if (typeof bodyParsed === "object") {
|
||||
bodyParsed = this.parser(bodyParsed, "request", endpoint);
|
||||
|
||||
bodyParsed = {
|
||||
...bodyParsed,
|
||||
token: this._token,
|
||||
token: this._token ?? "",
|
||||
};
|
||||
|
||||
if (bodyParsed.token === "")
|
||||
delete bodyParsed.token;
|
||||
|
||||
bodyParsed = JSON.stringify(bodyParsed);
|
||||
}
|
||||
|
||||
@@ -88,37 +107,12 @@ export default class uwuzu<
|
||||
endpoint as string,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
cache: "no-store",
|
||||
body: bodyParsed,
|
||||
}
|
||||
);
|
||||
|
||||
let res = await req.json();
|
||||
|
||||
if (res["0"] !== undefined && res.success === true) {
|
||||
res.success = undefined;
|
||||
|
||||
const data = Object.values(res).filter(Boolean);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
if (res.favorite_list !== undefined && res.success === true) {
|
||||
res.success = undefined;
|
||||
|
||||
const list = res.favorite_list.split(",");
|
||||
|
||||
return {
|
||||
success: true,
|
||||
favorite_list: list,
|
||||
};
|
||||
}
|
||||
const res = this.parser(await req.json(), "response", endpoint);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import uwuzuError from "@/lib/error";
|
||||
import uwuzuError from "./error";
|
||||
|
||||
export function generateURL(
|
||||
origin: string,
|
||||
|
||||
@@ -17,13 +17,6 @@
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./*"],
|
||||
"1.6.8/*": ["./1.6.8/*"],
|
||||
"1.6.9/*": ["./1.6.8/*"],
|
||||
"1.6.10/*": ["./1.6.8/*"],
|
||||
"1.6.11/*": ["./1.6.8/*"],
|
||||
},
|
||||
},
|
||||
"tsc-alias": {
|
||||
"resolveFullPaths": true,
|
||||
|
||||
Reference in New Issue
Block a user