auron
Version:
Interact with your ATProto labeler from your terminal
93 lines (92 loc) • 4.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.queueCommand = void 0;
const commander_1 = require("commander");
const db_1 = require("../services/db");
const loader_1 = require("../utils/loader");
const queue_1 = require("../controllers/queue");
const file_1 = require("../services/file");
exports.queueCommand = new commander_1.Command("queue");
exports.queueCommand
.command("sync")
.option("-n, --count <number>", "Max number of items from the queue to sync", (value) => parseInt(value, 10), 100)
.option("--cursor <string>", "Cursor to start fetching from")
.option("-t, --takendown", "Only sync takendown subjects")
.option("--reviewState <string>", "Items in specific review state to be synced")
.option("--data-only", "Only fetch record and repo data, without syncing queue items")
.description("Fetch your ozone queue and store it in the local database")
.action(async (options) => {
if (!options.dataOnly) {
const subjects = await (0, queue_1.fetchQueueItems)(options);
await (0, queue_1.saveQueueItems)(subjects);
}
await (0, queue_1.fetchReposForSubjects)();
await (0, queue_1.fetchRecordsForSubjects)();
// await fetchProfilesForSubjects();
});
const addSubjectListOptions = (command) => {
return command
.option("-n, --count <number>", "Max number of items from the queue", (value) => parseInt(value, 10))
.option("-t, --type <type>", "Subject type filter, account or record", (value) => {
if (value && value !== "account" && value !== "record") {
throw new Error('Invalid type. Allowed values are "account" or "record".');
}
return value;
})
.option("--bio <keyword/text>", "Keyword to be matched in profile bio of subject")
.option("--keyword <keyword/text>", "Keyword to be matched anywhere in the profile bio/record content etc.")
.option("--email <text/regex>", "Text or regex to be matched anywhere in the email address of the author.")
.option("--columns <string>", "Comma separated names of columns to include in the output")
.option("--riskScore <number>", "Risk Score from threat signature filter", (value) => parseFloat(value))
.option("--lastCountry <string...>", "Last signin country of the user")
.option("-td, --takendown", "Only use takendown subjects")
.option("--cursor <string>", "Cursor to start fetching from");
};
addSubjectListOptions(exports.queueCommand.command("export"))
.description("Export queue from your local database")
.requiredOption("-f, --file <file>", "Export file path") // Make the file option required
.action(async (options) => {
(0, loader_1.withLoader)(`Exporting queue items...`, async (updateMessage) => {
const subjects = await (0, queue_1.processSubjects)(options);
if (subjects.length === 0) {
updateMessage(`No queue items found`);
return;
}
updateMessage(`Found ${subjects.length} queue items. Exporting to ${options.file}`);
if (options.file.endsWith(".csv")) {
const mapped = subjects.map((sub) => {
const { profile, ...rest } = sub;
return {
...rest,
name: sub.profile?.displayName || "",
};
});
await (0, file_1.writeCsvFile)(options.file, mapped);
}
else {
await (0, file_1.writeJsonFile)(options.file, subjects);
}
const lastItem = subjects[subjects.length - 1];
updateMessage(`${subjects.length} queue items exported to ${options.file}. Cursor: ${lastItem.lastReportedAt}`);
});
});
addSubjectListOptions(exports.queueCommand.command("pipe"))
.description("Output 1 item at a time from your queue to stdout")
.action(async (options) => {
const subjects = await (0, queue_1.processSubjects)(options);
if (subjects.length === 0) {
return;
}
for (const subject of subjects) {
console.log(JSON.stringify(subject));
}
});
exports.queueCommand
.command("clear")
.description("Clear your locally stored queue")
.action(async () => {
(0, loader_1.withLoader)(`Clearing queue items...`, async (logMessage) => {
await db_1.database.clearSubjects();
logMessage("Queue items cleared from the database");
});
});