save current state

This commit is contained in:
2025-07-16 23:14:48 +02:00
parent fc814a77d7
commit d34cde54fb
6 changed files with 588 additions and 2 deletions

22
.vscode/launch.json vendored
View File

@ -1,3 +1,21 @@
/*{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${file}"
]
}
]
}
*/
{ {
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
@ -10,8 +28,8 @@
"ts-node/register" "ts-node/register"
], ],
"args": [ "args": [
"${workspaceFolder}/src/index.ts" "./src/apitest.ts"
] ]
} }
] ]
} }

303
package-lock.json generated
View File

@ -8,6 +8,12 @@
"name": "typescript-cli-boilerplate", "name": "typescript-cli-boilerplate",
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": {
"@types/axios": "^0.9.36",
"axios": "^1.10.0",
"dotenv": "^17.2.0",
"form-data": "^4.0.3"
},
"bin": { "bin": {
"my-cli": "dist/index.js" "my-cli": "dist/index.js"
}, },
@ -86,6 +92,12 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/axios": {
"version": "0.9.36",
"resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.9.36.tgz",
"integrity": "sha512-NLOpedx9o+rxo/X5ChbdiX6mS1atE4WHmEEIcR9NLenRVa5HoVjAvjafwU3FPTqnZEstpoqCaW7fagqSoTDNeg==",
"license": "MIT"
},
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "18.19.119", "version": "18.19.119",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.119.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.119.tgz",
@ -129,6 +141,48 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"license": "MIT"
},
"node_modules/axios": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.10.0.tgz",
"integrity": "sha512-/1xYAC4MP/HEG+3duIhFr4ZQXR4sQXOIe+o6sdqzeykGLx6Upp/1p8MHqhINOvGeP7xyNHe7tsiJByc4SSVUxw==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"license": "MIT",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/create-require": { "node_modules/create-require": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
@ -136,6 +190,15 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"license": "MIT",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/diff": { "node_modules/diff": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
@ -146,6 +209,210 @@
"node": ">=0.3.1" "node": ">=0.3.1"
} }
}, },
"node_modules/dotenv": {
"version": "17.2.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.0.tgz",
"integrity": "sha512-Q4sgBT60gzd0BB0lSyYD3xM4YxrXA9y4uBDof1JNYGzOXrQdQ6yX+7XIAqoFOGQFOTK1D3Hts5OllpxMDZFONQ==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-set-tostringtag": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.6",
"has-tostringtag": "^1.0.2",
"hasown": "^2.0.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/follow-redirects": {
"version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"license": "MIT",
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.3.tgz",
"integrity": "sha512-qsITQPfmvMOSAdeyZ+12I1c+CKSstAFAwu+97zrnWAbIr5u8wfsExUzCesVLC8NgHuRUqNN4Zy6UPWUTRGslcA==",
"license": "MIT",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"es-set-tostringtag": "^2.1.0",
"hasown": "^2.0.2",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-tostringtag": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
"license": "MIT",
"dependencies": {
"has-symbols": "^1.0.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/make-error": { "node_modules/make-error": {
"version": "1.3.6", "version": "1.3.6",
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
@ -153,6 +420,42 @@
"dev": true, "dev": true,
"license": "ISC" "license": "ISC"
}, },
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"license": "MIT"
},
"node_modules/ts-node": { "node_modules/ts-node": {
"version": "10.9.2", "version": "10.9.2",
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz",

View File

@ -22,5 +22,11 @@
"@types/node": "^18.0.0", "@types/node": "^18.0.0",
"ts-node": "^10.8.0", "ts-node": "^10.8.0",
"typescript": "^4.7.4" "typescript": "^4.7.4"
},
"dependencies": {
"@types/axios": "^0.9.36",
"axios": "^1.10.0",
"dotenv": "^17.2.0",
"form-data": "^4.0.3"
} }
} }

49
src/apitest.ts Normal file
View File

@ -0,0 +1,49 @@
import { AIdocClient } from './lib/AIdocClient';
const email = 'clodagh.byrne@100girls.club';
async function main() {
console.log(`Starting API test for email: ${email}`);
const client = new AIdocClient(email);
try {
await client.authenticate();
console.log('Authenticated user:', client.user);
if (client.user) {
console.log('--- Testing Follow/Unfollow ---');
const userIdToTest = 2; // Assuming user with ID 1 exists for testing
// Don't try to follow/unfollow self
if (client.user.id !== userIdToTest) {
console.log(`Following user ${userIdToTest}...`);
const followResponse = await client.follow(userIdToTest);
console.log(followResponse.message);
let following = await client.getFollowing(client.user.id);
console.log('Current following:', following.map(u => u.id));
console.log(`Unfollowing user ${userIdToTest}...`);
const unfollowResponse = await client.unfollow(userIdToTest);
console.log(unfollowResponse.message);
following = await client.getFollowing(client.user.id);
console.log('Current following:', following.map(u => u.id));
} else {
console.log('Skipping follow/unfollow test to avoid self-action.');
}
const followers = await client.getFollowers(client.user.id);
console.log('Followers:', followers.length);
const following = await client.getFollowing(client.user.id);
console.log('Following:', following.length);
}
console.log('API test finished successfully.');
} catch (error) {
console.error('API test failed:', error);
}
}
main();

139
src/lib/AIdocClient.ts Normal file
View File

@ -0,0 +1,139 @@
import axios from 'axios';
import * as dotenv from 'dotenv';
import fs from 'fs/promises';
import path from 'path';
import FormData from 'form-data';
import { ApiMethod, Follower, FollowersResponse, FollowingResponse, SignInResponse, User, VerifyResponse } from './interfaces';
// Load environment variables from .env file
dotenv.config();
const API_BASE_URL = 'https://aidol.club/api';
const SECRET_KEY = 'ECUp5AQgnHlt5qn8U2HUfzjxsyLVQSUX';
export class AIdocClient {
private email: string;
private token: string | null = null;
public user: User | null = null;
constructor(email: string) {
this.email = email;
}
private async _api<T>(method: ApiMethod, endpoint: string, data?: any): Promise<T> {
if (!this.token) {
throw new Error('Authentication token not found. Please authenticate first.');
}
const url = `${API_BASE_URL}/${endpoint}`;
const headers: any = {
'Authorization': `Bearer ${this.token}`,
};
if (data instanceof FormData) {
Object.assign(headers, data.getHeaders());
} else {
headers['Content-Type'] = 'application/json';
}
try {
const response = await axios({
method,
url,
data,
headers,
});
return response.data;
} catch (error: any) {
const errorMessage = error.response?.data?.message || error.message;
console.error(`API call failed for ${method} ${endpoint}:`, errorMessage);
throw new Error(`API call failed: ${errorMessage}`);
}
}
public async authenticate(): Promise<void> {
try {
console.log(`Authenticating ${this.email}...`);
// 1. Sign In
const signInResponse = await axios.post<SignInResponse>(`${API_BASE_URL}/auth/signin`, {
email: this.email,
secret_key: SECRET_KEY,
});
const signInKey = signInResponse.data.signin_key;
if (!signInKey) {
throw new Error(`Sign-in failed for ${this.email}: No signin_key received.`);
}
console.log(`Sign-in successful, received sign-in key.`);
// 2. Verify
const verifyResponse = await axios.post<VerifyResponse>(`${API_BASE_URL}/auth/verify`, {
email: this.email,
key: signInKey,
});
this.token = verifyResponse.data.token;
if (!this.token) {
throw new Error(`Verification failed for ${this.email}: Missing token.`);
}
this.user = await this.me();
console.log(`Authentication successful for ${this.email}.`);
} catch (error: any) {
const errorMessage = error.response?.data?.message || error.message;
console.error(`Authentication failed for ${this.email}:`, errorMessage);
throw new Error(`Authentication failed: ${errorMessage}`);
}
}
public async me(): Promise<User> {
return this._api<User>(ApiMethod.GET, 'auth/me');
}
public async getFollowers(userId: number): Promise<Follower[]> {
let page = 1;
const allFollowers: Follower[] = [];
let totalPages = 1;
while (page <= totalPages) {
const endpoint = `users/${userId}/followers?page=${page}`;
const response = await this._api<FollowersResponse>(ApiMethod.GET, endpoint);
allFollowers.push(...response.followers);
totalPages = response.totalPages;
page++;
}
return allFollowers;
}
public async getFollowing(userId: number): Promise<Follower[]> {
let page = 1;
const allFollowing: Follower[] = [];
let totalPages = 1;
while (page <= totalPages) {
const endpoint = `users/${userId}/following?page=${page}`;
const response = await this._api<FollowingResponse>(ApiMethod.GET, endpoint);
allFollowing.push(...response.following);
totalPages = response.totalPages;
page++;
}
return allFollowing;
}
public async follow(userId: number): Promise<{ message: string }> {
const endpoint = `users/${userId}/follow`;
return this._api<{ message: string }>(ApiMethod.POST, endpoint);
}
public async unfollow(userId: number): Promise<{ message: string }> {
const endpoint = `users/${userId}/follow`;
return this._api<{ message: string }>(ApiMethod.DELETE, endpoint);
}
}

71
src/lib/interfaces.ts Normal file
View File

@ -0,0 +1,71 @@
export interface ModelDetail {
id: string; // Assuming 'id' is the directory name and used for photo lookup
email: string;
name: string;
gender: string;
description_text: string;
socialnetwork_id?: string; // Will be added by the script
[key: string]: any; // Allow other properties
}
export interface SignInResponse {
signin_key: string;
}
export interface User {
id: number;
email: string;
name: string;
avatar_url: string;
gender: string;
description_text: string;
created_at: string;
updated_at: string;
credit: string;
purchasedBooks: any[];
isAdmin: boolean;
}
export interface VerifyResponse {
message: string;
token: string;
user: User;
}
export interface FileUploadResponse {
data: {
files: Array<{ url: string;[key: string]: any }>;
filename: string;
}
}
export enum ApiMethod {
GET = 'get',
POST = 'post',
PUT = 'put',
DELETE = 'delete',
}
export interface Follower {
id: number;
email: string;
name: string;
avatar_url: string;
followed_at: string;
}
export interface FollowersResponse {
followers: Follower[];
total: number;
page: number;
limit: number;
totalPages: number;
}
export interface FollowingResponse {
following: Follower[];
total: number;
page: number;
limit: number;
totalPages: number;
}