diff --git a/src/tools/action/add.ts b/src/tools/action/add.ts index 2187a73..b9995ed 100644 --- a/src/tools/action/add.ts +++ b/src/tools/action/add.ts @@ -2,7 +2,7 @@ import { rest, rootStatus } from '../../prepare' import Logger from '../../utils/Logger' async function run() { - const content = process.argv[2] + const [,,content, visibility] = process.argv if (!content) { Logger.error('require content') return @@ -11,7 +11,7 @@ async function run() { const status = await rest.postStatus({ in_reply_to_id: rootStatus, status: content, - visibility: 'private' + visibility: visibility as any || 'direct' }) Logger.info('action added', { id: status.id, tags: status.tags.map(t => t.name).reverse() }) } diff --git a/src/tools/data/push.ts b/src/tools/data/push.ts index 1ab0da5..e20c1af 100644 --- a/src/tools/data/push.ts +++ b/src/tools/data/push.ts @@ -3,20 +3,32 @@ import { rest, rootStatus } from '../../prepare' import Logger from '../../utils/Logger' async function run() { - const [,, file, title] = process.argv + const [,, file, title, visibility] = process.argv if (!file) { Logger.error('require file') return } + + const post = async (in_reply_to_id: string, status: string) => rest.postStatus({ + in_reply_to_id, status, + visibility: visibility as any || 'direct' + }).then(s => s.id) + const data = JSON.parse(fs.readFileSync(file, 'utf8')) - const ok = data.map((l: any) => Object.entries(l).map(([lang, message]) => `[${lang}] ${message}`).join('\n')) - Logger.info('data', ok) - /* - const status = await rest.postStatus({ - in_reply_to_id: rootStatus, - status: content, - visibility: 'private' - }) - Logger.info('action added', { id: status.id, tags: status.tags.map(t => t.name).reverse() })*/ + const folder = await post(rootStatus, title || file) + for (const row of data) { + if (typeof row === 'string') { + await post(folder, row) + } else if (typeof row === 'object') { + const content = '\n' + Object.entries(row).map(([lang, message]) => `[${lang}] ${message}`).join('\n\n') + const global = await post(folder, content) + for (const [lang, message] of Object.entries(row)) { + await post(global, `${message} #${lang}`) + } + } else { + throw new Error('bad type ' + typeof row) + } + } + Logger.info('data added', folder) } run() \ No newline at end of file