Skip to content
This repository was archived by the owner on Jul 20, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
"name": "amino.ts",
"description": "Unofficial client for working with rest-api aminoapps",
"version": "1.0.0",

"homepage": "https://github.com/osm1um/amino.ts/#readme",

"author": "osm1um",
"main": "build/index.js",

"scripts": {
"build": "tsc --project tsconfig.json",
"start": "node .",
"test": "node . --requests-debug"
},

"dependencies": {
"@types/node": "^13.11.0",
"node-fetch": "^2.6.0",
"sync-request": "^6.1.0",
"typescript": "^3.8.3",
"ws": "^7.2.3"
Expand Down
63 changes: 63 additions & 0 deletions src/components/APIEndpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { blog_type, thread_type, thread_sort } from "../components/community/community"
/*
*Static object that can build endpoint
*/
export class APIEndpoint {
//[prefix]
static Prefix: string = "http://service.narvii.com/api/v1";
// [auth]
static Login: string = APIEndpoint.Prefix + "/g/s/auth/login";
static JoiniedCommunities: string = APIEndpoint.Prefix + `/g/s/community/joined`


// [COMPLILE ENDPOINTS]
static CompileGetBlog(blogId: string, communityId: number): string {
return APIEndpoint.Prefix + `/x${communityId}/s/blog/${blogId}`;
}
static CompileGetComent(comentId: string, blogId: string): string {
return APIEndpoint.Prefix + `/x${comentId}/s/blog/${blogId}/comment/${comentId}`;
}
static CompileGetComents(comentId: string, communityId: number, start: number, size: number): string {
return APIEndpoint.CompileGetBlog(comentId, communityId) + `/comment?start=${start}&size=${size}`;
}

static CompileProfile(id: number, userId: string): string {
return APIEndpoint.Prefix + `/x${id}/s/user-profile/${userId}`;
}
static CompileGetOnlineMembers(communityId: number, start: number, size: number): string {
return APIEndpoint.Prefix + `/x${communityId}/s/live-layer?topic=ndtopic%3Ax${communityId}%3Aonline-members&start=${start}&size=${size}`;
}
static CompileGetBlogs(communityId: number, type: blog_type, start: number, size: number): string {
return APIEndpoint.Prefix + `/x${communityId}/s/feed/${type}?start=${start}&size=${size}`;
}
static CompileGetThreads(communityId: number, type: thread_type, sort: thread_sort, start: number, size: number): string {
return APIEndpoint.Prefix + `/x${communityId}/s/chat/thread?type=${type}&filterType=${sort}&start=${start}&size=${size}`;
}
static CompileGetCommunity(communityId: number): string {
return APIEndpoint.Prefix + `/g/s-x${communityId}/community/info`;
}
static CompileCreateThread(communityId: number): string {
return APIEndpoint.Prefix + `/x${communityId}/s/chat/thread`;
}
static CompileGetRecentBlogs(id: string, communityId: number, start: number, size: number): string {
return APIEndpoint.Prefix + `/x${communityId}/s/blog?type=user&q=${id}&start=${start}&size=${size}`;
}
static CompileGetMember(id: string, communityId: number): string {
return APIEndpoint.Prefix + `/x${communityId}/s/user-profile/${id}?action=visit`;
}
static CompileMessageWithId(messageId: string, threadId: any, communityId: number): string {
return APIEndpoint.CompileMessage(threadId, communityId) + `/${messageId}`;
}
static CompileMessage(threadId: any, communityId: number): string {
return APIEndpoint.Prefix + `/x${communityId}/s/chat/thread/${threadId}/message`;
}
static CompileGetMessageList(threadId: any, communityId: number, count: number): string {
return APIEndpoint.Prefix + `/x${communityId}/s/chat/thread/${threadId}/message?v=2&pagingType=t&size=${count}`;
}
static CompileThread(threadId: any, communityId: number): string {
return APIEndpoint.Prefix + `/x${communityId}/s/chat/thread/${threadId}`;
}
static CompileThreadWithMember(threadId: any, communityId: number, memberID: string): string {
return APIEndpoint.CompileThread(threadId, communityId) + `/member/${memberID}`;
}
}
17 changes: 9 additions & 8 deletions src/components/blog/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import AminoClient, {
IAminoStorage,
AminoMember,
AminoCommunity,
IAminoCommentStorage
AminoCommentStorage
} from "./../../index"

import {APIEndpoint} from "../APIEndpoint"
/**
* Class for working with blogs
*/
Expand Down Expand Up @@ -43,21 +43,22 @@ export class AminoBlog {
* @param {number} [start] start position
* @param {number} [size] count by start
*/
public get_comments(start: number = 1, size: number = 10): IAminoCommentStorage {
let response = request("GET", `https://service.narvii.com/api/v1/x${this.community.id}/s/blog/${this.id}/comment?start=${start}&size=${size}`, {
public get_comments(start: number = 1, size: number = 10): AminoCommentStorage {

let response = request("GET", APIEndpoint.CompileGetComents(this.id,this.community.id,start,size), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
}
});

return new IAminoCommentStorage(this.client, this.community, this, response.commentList);
return new AminoCommentStorage(this.client, this.community, this, response.commentList);
}

/**
* Method for updating the structure, by re-requesting information from the server
*/
public refresh(): AminoBlog {
let response = request("GET", `https://service.narvii.com/api/v1/x${this.community.id}/s/blog/${this.id}`, {
let response = request("GET", APIEndpoint.CompileGetBlog(this.id,this.community.id), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
}
Expand Down Expand Up @@ -95,9 +96,9 @@ export class AminoBlog {
/**
* Class for storing blog objects
*/
export class IAminoBlogStorage extends IAminoStorage<AminoBlog> {
export class AminoBlogStorage extends IAminoStorage<AminoBlog> {
constructor(client: AminoClient, community: AminoCommunity, array?: any) {
super(client, IAminoBlogStorage.prototype);
super(client, AminoBlogStorage.prototype);
if (array) {
let members: AminoMember[] = community.cache.members.get();
array.forEach(struct => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/comment/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AminoClient, {
AminoCommunity,
AminoBlog
} from "./../../index"

import {APIEndpoint} from "../APIEndpoint"
/**
* Class for working with comments
*/
Expand Down Expand Up @@ -39,7 +39,7 @@ export class AminoComment {
* Method for updating the structure, by re-requesting information from the server
*/
public refresh(): AminoComment {
let response = request("GET", `https://service.narvii.com/api/v1/x${this.id}/s/blog/${this.blog.id}/comment/${this.id}`, {
let response = request("GET", APIEndpoint.CompileGetComent(this.id,this.blog.id), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
}
Expand All @@ -66,9 +66,9 @@ export class AminoComment {
/**
* Class for storing comment objects
*/
export class IAminoCommentStorage extends IAminoStorage<AminoComment> {
export class AminoCommentStorage extends IAminoStorage<AminoComment> {
constructor(client: AminoClient, community: AminoCommunity, blog: AminoBlog, array?: any) {
super(client, IAminoCommentStorage.prototype);
super(client, AminoCommentStorage.prototype);
if (array) {
let members: AminoMember[] = community.cache.members.get();
array.forEach(struct => {
Expand Down
51 changes: 27 additions & 24 deletions src/components/community/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import AminoClient, {
IAminoCache,
IAminoStorage,
AminoMember,
IAminoMemberStorage,
AminoMemberStorage,
AminoThread,
IAminoThreadStorage,
IAminoBlogStorage
AminoThreadStorage,
AminoBlogStorage,
requestAsync
} from "./../../index"

declare type blog_type = ('featured-more' | 'featured' | 'blog-all');
declare type thread_sort = ('recommended' | 'popular' | 'latest');
declare type thread_type = ('joined-me' | 'public-all');
import { APIEndpoint } from "../APIEndpoint"
export declare type blog_type = ('featured-more' | 'featured' | 'blog-all');
export declare type thread_sort = ('recommended' | 'popular' | 'latest');
export declare type thread_type = ('joined-me' | 'public-all');

/**
* Class for working with communities
Expand Down Expand Up @@ -61,7 +62,7 @@ export class AminoCommunity {
* @param {string} [nickname] string
*/
public set_nickname(nickname: string) {
let response = request("POST", `https://service.narvii.com/api/v1/x${this.id}/s/user-profile/${this.me.id}`, {
let response = request("POST", APIEndpoint.CompileProfile(this.id,this.me.id), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
},
Expand All @@ -77,8 +78,8 @@ export class AminoCommunity {
* Set account description
* @param {string} [description] string
*/
public set_description(description: string) {
let response = request("POST", `https://service.narvii.com/api/v1/x${this.id}/s/user-profile/${this.me.id}`, {
public async set_description(description: string) : Promise<any> {
return await requestAsync("POST", APIEndpoint.CompileProfile(this.id,this.me.id), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
},
Expand All @@ -95,14 +96,14 @@ export class AminoCommunity {
* @param {number} [start] pointer to the starting index to read the list
* @param {number} [size] number of records to read
*/
public get_online_members(start: number = 0, size: number = 10): IAminoMemberStorage {
let response = request("GET", `https://service.narvii.com/api/v1/x${this.id}/s/live-layer?topic=ndtopic%3Ax${this.id}%3Aonline-members&start=${start}&size=${size}`, {
public get_online_members(start: number = 0, size: number = 10): AminoMemberStorage {
let response = request("GET", APIEndpoint.CompileGetOnlineMembers(this.id,start,size), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
}
});

return new IAminoMemberStorage(this.client, this, response.userProfileList);
return new AminoMemberStorage(this.client, this, response.userProfileList);
}

/**
Expand All @@ -111,14 +112,15 @@ export class AminoCommunity {
* @param {number} [start] start position
* @param {number} [size] number of blogs to read
*/
public get_blogs(type: blog_type, start: number = 1, size: number = 10): IAminoBlogStorage {
let response = request("GET", `https://service.narvii.com/api/v1/x${this.id}/s/feed/${type}?start=${start}&size=${size}`, {
public get_blogs(type: blog_type, start: number = 1, size: number = 10): AminoBlogStorage {

let response = request("GET", APIEndpoint.CompileGetBlogs(this.id,type,start,size), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
}
});

return new IAminoBlogStorage(this.client, this, response.blogList);
return new AminoBlogStorage(this.client, this, response.blogList);
}

/**
Expand All @@ -128,22 +130,23 @@ export class AminoCommunity {
* @param {number} [size] number of records to read
* @param {thread_sort} [sort] sorting type
*/
public get_threads(type: thread_type, sort: thread_sort = "latest", start: number = 1, size: number = 10): IAminoThreadStorage {
let response = request("GET", `https://service.narvii.com/api/v1/x${this.id}/s/chat/thread?type=${type}&filterType=${sort}&start=${start}&size=${size}`, {
public get_threads(type: thread_type, sort: thread_sort = "latest", start: number = 1, size: number = 10): AminoThreadStorage {
let response = request("GET", APIEndpoint.CompileGetThreads(this.id,type,sort,start,size), {
"headers": {
"NDCAUTH": "sid=" + this.client.session,
"NDCDEVICEID": this.client.device
}
});

return new IAminoThreadStorage(this.client, this, response.threadList)
return new AminoThreadStorage(this.client, this, response.threadList)
}

/**
* Method for updating the structure, by re-requesting information from the server
*/
public refresh(): AminoCommunity {
let response = request("GET", `https://service.narvii.com/api/v1/g/s-x${this.id}/community/info`, {

let response = request("GET", APIEndpoint.CompileGetCommunity(this.id), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
}
Expand Down Expand Up @@ -181,10 +184,10 @@ export class AminoCommunity {
/**
* Class for storing community objects
*/
export class IAminoCommunityStorage extends IAminoStorage<AminoCommunity> {
export class AminoCommunityStorage extends IAminoStorage<AminoCommunity> {
constructor(client: AminoClient) {
super(client, IAminoCommunityStorage.prototype);
request("GET", `https://service.narvii.com/api/v1/g/s/community/joined`, {
super(client, AminoCommunityStorage.prototype);
request("GET", APIEndpoint.JoiniedCommunities, {
"headers": {
"NDCAUTH": "sid=" + this.client.session
}
Expand All @@ -197,7 +200,7 @@ export class IAminoCommunityStorage extends IAminoStorage<AminoCommunity> {
* Call methods to update in structure objects
*/
public refresh() {
request("GET", `https://service.narvii.com/api/v1/g/s/community/joined`, {
request("GET", APIEndpoint.JoiniedCommunities, {
"headers": {
"NDCAUTH": "sid=" + this.client.session
}
Expand Down
19 changes: 10 additions & 9 deletions src/components/member/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import AminoClient, {
IAminoStorage,
AminoThread,
AminoCommunity,
IAminoBlogStorage
AminoBlogStorage
} from "./../../index"

import { APIEndpoint } from "../APIEndpoint"
/**
* Class for working with members
*/
Expand Down Expand Up @@ -46,7 +46,7 @@ export class AminoMember {
* @param {string} [initial_message] initial message for member
*/
public create_thread(initial_message: string): AminoThread {
let response = request("POST", `https://service.narvii.com/api/v1/x${this.community.id}/s/chat/thread`, {
let response = request("POST", APIEndpoint.CompileCreateThread(this.community.id), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
},
Expand All @@ -69,21 +69,22 @@ export class AminoMember {
* @param {number} [start] start position
* @param {number} [size] number of blogs to read
*/
public get_recent_blogs(start: number = 0, size: number = 10): IAminoBlogStorage {
let response = request("GET", `https://service.narvii.com/api/v1/x${this.community.id}/s/blog?type=user&q=${this.id}&start=${start}&size=${size}`, {
public get_recent_blogs(start: number = 0, size: number = 10): AminoBlogStorage {

let response = request("GET", APIEndpoint.CompileGetRecentBlogs(this.id,this.community.id,start,size), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
}
});

return new IAminoBlogStorage(this.client, this.community, response.blogList);
return new AminoBlogStorage(this.client, this.community, response.blogList);
}

/**
* Method for updating the structure, by re-requesting information from the server
*/
public refresh(): AminoMember {
let response = request("GET", `https://service.narvii.com/api/v1/x${this.community.id}/s/user-profile/${this.id}?action=visit`, {
let response = request("GET", APIEndpoint.CompileGetMember(this.id,this.community.id), {
"headers": {
"NDCAUTH": "sid=" + this.client.session
}
Expand Down Expand Up @@ -118,9 +119,9 @@ export class AminoMember {
/**
* Class for storing members objects
*/
export class IAminoMemberStorage extends IAminoStorage<AminoMember> {
export class AminoMemberStorage extends IAminoStorage<AminoMember> {
constructor(client: AminoClient, community: AminoCommunity, array?: any) {
super(client, IAminoMemberStorage.prototype);
super(client, AminoMemberStorage.prototype);
if (array) {
let members: AminoMember[] = community.cache.members.get();
array.forEach(struct => {
Expand Down
Loading