l7note
Version:
Access your notion notes quick
121 lines (120 loc) • 4.88 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getList = void 0;
const client_1 = require("@notionhq/client");
const chalk_1 = __importDefault(require("chalk"));
const process_1 = require("process");
const displayNotes_js_1 = require("../displayNotes.js");
const getSettingValueByName_js_1 = require("../helper/getSettingValueByName.js");
const Note_js_1 = require("../Note.js");
const setup_js_1 = require("../setup.js");
const addTagText = (text, color) => {
switch (color) {
case 'red':
return `${chalk_1.default.bgHex('#ffe2dd').black(text)} `;
case 'pink':
return `${chalk_1.default.bgHex('#F5E0E9').black(text)} `;
case 'purple':
return `${chalk_1.default.bgHex('#e8deee').black(text)} `;
case 'blue':
return `${chalk_1.default.bgHex('#D3E5EF').black(text)} `;
case 'green':
return `${chalk_1.default.bgHex('#DBEDDB').black(text)} `;
case 'yellow':
return `${chalk_1.default.bgHex('#FDECC8').black(text)} `;
case 'orange':
return `${chalk_1.default.bgHex('#fadec9').black(text)} `;
case 'brown':
return `${chalk_1.default.bgHex('#EEE0DA').black(text)} `;
}
};
const noteList = [];
const getList = () => __awaiter(void 0, void 0, void 0, function* () {
const notion = new client_1.Client({ auth: setup_js_1.globalConfig.token });
const databaseId = setup_js_1.globalConfig.dbId;
if (databaseId == undefined) {
return;
}
let filter = {};
if (setup_js_1.globalConfig.optionalArgs.length > 0) {
filter = {
and: [
{
property: 'Done',
checkbox: {
equals: false,
},
},
{
or: [
{
property: 'Title',
text: {
contains: (0, getSettingValueByName_js_1.getSettingValueByName)('-h'),
},
},
{
property: 'Text',
text: {
contains: (0, getSettingValueByName_js_1.getSettingValueByName)('-h'),
},
},
{
property: 'Tags',
multi_select: {
contains: (0, getSettingValueByName_js_1.getSettingValueByName)('-h'),
},
},
],
},
],
};
}
else {
filter = {
and: [
{
property: 'Done',
checkbox: {
equals: false,
},
},
],
};
}
const response = yield notion.databases.query({
database_id: databaseId,
filter: filter,
});
response.results.forEach((el) => {
const title = el.properties.Title.title
.map((texts) => texts.plain_text + ' ', '')
.join(' ');
const text = el.properties.Text.rich_text
.map((texts) => texts.plain_text + ' ', '')
.join(' ');
const tags = el.properties.Tags.multi_select
.map((tag) => addTagText(tag.name, tag.color), '')
.join(' ');
const note = new Note_js_1.Note(el.id, el.url, title, text, tags, el.created_time, el.last_edited_time);
noteList.push(note);
});
if (noteList.length <= 0) {
console.log(chalk_1.default.blue('No results found'));
(0, process_1.exit)(1);
}
(0, displayNotes_js_1.displayNotes)(noteList);
});
exports.getList = getList;