This is a SDK for GROWI written in node.js.
$ npm install @goofmint/growi-js
import { GROWI } from '@goofmint/growi-js';
const growi = new GROWI({apiToken: 'YOUR_API_TOKEN'});
Initialize parameters are as follows:
Parameter | Description |
---|---|
apiToken |
API token for GROWI. You can get it from the setting page of GROWI. |
url |
URL of GROWI. Default is http://localhost:3000 . |
path |
Endpoint path of Growi API. Default is / . |
const page = await growi.root();
page instanceof growi.Page; // true
const pages = await page.children();
pages[0] instanceof growi.Page; // true
page.contents('New contents');
await page.save();
const contents = await page.contents();
const newPage = await page.create({name: 'New page'});
await page.remove();
const tags = await page.tags();
await page.addTag('tag');
await page.removeTag('tag');
const comments = await page.comments();
const comment = page.comment();
comment.set('comment', 'New comment');
await comment.save();
comment.set('comment', 'Updated comment');
await comment.save();
await comment.remove();
const result = await growi.search({q: 'keyword'});
result.pages[0] instanceof growi.Page; // true
result.total // total number of pages
result.took // time taken for search
result.hitsCount // number of hits
const result = await growi.searchByTag('tag');
result.pages[0] instanceof growi.Page; // true
result.total // total number of pages
result.took // time taken for search
result.hitsCount // number of hits
const page = await growi.page({path: '/API Test'});
const fileName = 'logo.png';
const attachment = await page.upload(path.resolve("jest", fileName));
attachment // Attachment instance
const page = await growi.page({path: '/API Test'});
const res = await Attachment.list(page);
res.attachments // array of Attachment instances
res.limit // 10
res.page // 1
res.totalDocs // 20
const bol = await Attachment.limit(1024 * 1024 * 10);
bol // true
const a = await Attachment.find(attachment.id!);
a // Attachment instance
const user = await growi.currentUser();
const bookmarkFolders = await user.bookmarkFolders();
const bookmarkFolder = new BookmarkFolder();
bookmarkFolder.name = 'my folder';
await bookmarkFolder.save();
bookmarkFolder.name = 'my folder updated';
await bookmarkFolder.save();
await bookmarkFolder.remove();
const bookmarkFolder = new BookmarkFolder();
bookmarkFolder.name = 'Parent';
await bookmarkFolder.save();
const bookmarkFolder2 = new BookmarkFolder();
bookmarkFolder2.name = 'Child';
bookmarkFolder2.parent = bookmarkFolder;
await bookmarkFolder2.save();
Or
const bookmarkFolder = new BookmarkFolder();
bookmarkFolder.name = 'Parent';
const bookmarkFolder2 = new BookmarkFolder();
bookmarkFolder2.name = 'Child';
await bookmarkFolder.addFolder(bookmarkFolder2);
const bookmarkFolder3 = new BookmarkFolder();
bookmarkFolder3.name = 'New parent';
bookmarkFolder3.parent = bookmarkFolder2;
await bookmarkFolder3.save();
await bookmarkFolder.fetch();
const bookmarks = await user.bookmarks();
const page = await growi.root();
const info = await page.bookmarkInfo();
info.bookmarkCount // number of bookmarks
info.bookmarked // true if the page is bookmarked by the current user
info.users // array of users who bookmarked the page
await user.bookmark(page); // unbookmark
await user.bookmark(page, false); // unbookmark
const bol = await user.isBookmarked(page);
const folder = new BookmarkFolder();
folder.name = 'my folder';
await folder.save();
await folder.addPage(page);
MIT