@ibaraki-douji/fanbox
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Fanbox

Get infos from Pixiv Fanbox

Getting started

npm i @ibaraki-douji/fanbox --save

Usage

Import the lib

const Fanbox = require('@ibaraki-douji/fanbox').default

Init the fanbox

const Fanbox = require('@ibaraki-douji/fanbox').default

const fanbox = new Fanbox();

I will not show the import for the other exemple but you need it at least once.

Login to your account

const fanbox = new Fanbox();

fanbox.login("your cookies");

You can find how to get your cookies here. Why you want to login ? To get all subscriptions infos and account related actions (likes, follows)

Get User

const fanbox = new Fanbox();

const options = {
  withPosts: true,
  withPlans: true,
  withShop: true
};

fanbox.getUser("creatorID", options).then(user => {
    
});

Some of the fields way be null or undefined if they are not fetched All of the options are optionnals and the options agrument is optionnal too.

Get Self User

const fanbox = new Fanbox();

const options = {
  withPosts: true,
  withPlans: true,
  withShop: true
};

fanbox.getSelfUser(options).then(selfUser => {
    
});

Some of the fields way be null or undefined if they are not fetched All of the options are optionnals and the options agrument is optionnal too.

Get Post

const fanbox = new Fanbox();

fanbox.getPost("postID").then(post => {
    
})

Return a ImagePost or EntryPost or ArticlePost, if none of the type post is found it will return a Post with all the data from the request. If the creator from the post already exists it will add it to the stored user.

Classes / Interfaces

Fanbox

{
    public users: Array<User> = [];
    login: (cookies: string) => void;
    getUser: (creatorId: string, options?: {
        withPosts?: boolean,
        withPlans?: boolean,
        withShop?: boolean
    }) => Promise<User>;
    getPost: (id: string) => Promise<Post>
}

User

{
    name: string;
    followed: boolean;
    avatarURL: string;
    backgroundURL: string;
    references: Array<string>;
    plans: Array<Plan>;
    posts: {[k: string]: Post};
    shop: Shop;
    pixivId: string;
    creatorId: string;
    getShop: () => Promise<void>;
    getPlans: () => Promise<void>;
    getPosts: () => Promise<void>;
}

SelfUser

{
    twitter: {
        enabled: true,
        id: string,
        name: string,
        profileImageUrl: string,
        screenName: string,
        url: string
    } | {
        enabled: false
    };
    name: string;
    id: string;
    avatarUrl: string;
    followedCreatorIds: Array<string>;
    supportedCreatorIds: Array<string>;
    r18: boolean;
    unreadNewsletterCount: number;
    unreadMessageCount: number;
    unreadBellCount: number;
    creatorId: string;
    creator: User
}

Plan

{
    name: string;
    description: string;
    price: number;
    iconURL: string;
}

Shop

{
    name: string;
    url: string;
    items: Array<{
        adult: boolean,
        description: string,
        id: number,
        image: string,
        market_url: string,
        name: string,
        price: number,
        url: string,
        published_at: Date
    }>;
    total: number;
}

Post

{
    name: string;
    date: Date;
    price: number;
    iconURL: string;
    description: string;
    tags: Array<string>;
    type: string;
    id: string;
    liked: boolean;
    likeCount: number;
}

ImagePost (extends Post)

{
    text: string;
    images: Array<{
        id: string,
        extention: string,
        width: number,
        height: number,
        originalUrl: string,
        thumbnailUrl: string
    }>;
}

EntryPost (extends Post)

{
    html: string;
}

ArticlePost (extends Post)

blocks: Array<{
        type: 'p',
        text: string,
        styles?: Array<{
            type: string,
            offset: number,
            length: number
        }>,
        links?: Array<{
            offset: number,
            length: number,
            url: string
        }>
    } | {
        type: 'image',
        imageId: string
    } | {
        type: "header",
        text: string
    }>;
    imageMap: {
        [k: string]: {
            id: string,
            extension: "png" | "jpeg",
            width: number,
            height: number,
            originalUrl: string,
            thumbnailUrl: string
        }
    };
    fileMap: {
        [k: string]: {
            id: string,
            name: string,
            extension: string,
            size: number,
            url: string
        }
    };
    embedMap: {
        [k: string]: {
            id: string,
            serviceProvider: string,
            contentId: string
        }
    };
    urlEmbedMap: {
        [k: string]: {
            id: string,
            type: "fanbox.post",
            postInfo: {
                id: string,
                title: string,
                feeRequired: string,
                hasAdultContent: boolean,
                creatorId: string,
                coverImageUrl: string,
                excerpt: string,
                publishedDatetime: string
            }
        }
    };

Exemple

const Fanbox = require('@ibaraki-douji/fanbox').default
const fanbox = new Fanbox();

// MAKE A ASYNC FUNCTION AT START
(async () => {
   const user = await fanbox.getUser("qtonagi", {
       withPlans: false,
       withShop: false
   });
   console.log(user);
   console.log("Total posts from " + user.name + " : " + Object.keys(user.posts).length);
})()

More Help and Support

Discord : https://discord.gg/mD9c4zP4Er

Ask me for an update or to fix a bug in the Discord server

Package Sidebar

Install

npm i @ibaraki-douji/fanbox

Weekly Downloads

0

Version

1.2.0

License

ISC

Unpacked Size

47.8 kB

Total Files

40

Last publish

Collaborators

  • ibaraki-douji