Go to file
Gergő Móricz 5b1d39eefd
Update lib.js
2024-06-14 21:08:14 +02:00
.husky Setup Prettier 2022-07-31 21:51:51 +02:00
.vscode Setup Prettier 2022-07-31 21:51:51 +02:00
lib run prettier 2022-07-31 21:54:56 +02:00
.gitignore Initial commit 2022-06-29 14:24:33 +02:00
.prettierrc.json Setup Prettier 2022-07-31 21:51:51 +02:00
LICENSE Initial commit 2022-06-29 14:10:14 +02:00
README.md Document Post.update() and add it to README 2024-02-26 20:18:38 -05:00
lib.js Update lib.js 2024-06-14 21:08:14 +02:00
lint-staged.config.js Setup Prettier 2022-07-31 21:51:51 +02:00
package-lock.json Merge branch 'prettier' into files-upload 2022-07-31 21:54:17 +02:00
package.json Bump version to 0.0.3 2022-09-09 16:25:07 +02:00

README.md

cohost.js

Unofficial API for cohost.org

Install

npm i cohost

Usage

const cohost = require("cohost");

(async function () {
  // Create User and authenticate
  let user = new cohost.User();
  await user.login("YOUR_EMAIL", "YOUR_PASSWORD");

  // Get first Project of user
  let [project] = await user.getProjects();

  // Create Post
  let myPostID = await cohost.Post.create(project, {
    postState: 1,
    headline: "hello world from cohost.js",
    adultContent: false,
    blocks: [],
    cws: [],
    tags: []
  });

  // Edit Post
  await cohost.Post.update(project, myPostID, {
    postState: 1,
    headline: "Hello world from cohost.js!",
    adultContent: false,
    blocks: [],
    cws: [],
    tags: ["cohost.js"]
  });

  // Get Posts of Project
  let posts = await project.getPosts();

  // Create a draft with attachments

  // 1. Create a draft
  const draftId = await cohost.Post.create(myProject, basePost);

  // 2. Upload the attachment
  const attachmentData = await myProject.uploadAttachment(
    draftId,
    path.resolve(__dirname, "./02-15_One_pr.png")
  );

  // 3. Add the attachment block to the draft and publish it
  await cohost.Post.update(myProject, draftId, {
    ...basePost,
    postState: 1,
    blocks: [
      ...basePost.blocks,
      { type: "attachment", attachment: { ...attachmentData } }
    ]
  });
})();

Features

Works:

  • Logging in
  • Getting the posts of a project
  • Creating a post
  • Editing a post

Doesn't work:

  • Sharing a post: possible, haven't done it
  • Liking a post: possible, haven't done it
  • Getting notifications: possible, haven't done it
  • Getting the home feed: possible, haven't done it
  • Editing profiles: possible, haven't done it
  • Getting followers and following: possible, haven't done it
  • Getting bookmarks and bookmarking: possible, haven't done it
  • Getting a post by its ID: seems impossible? endpoint seems to be disabled
  • Getting posts from a tag: haven''t checked
  • ...everything else