Expose import as a background admin job with status polling, dry-run and optional publish; share logic with the CLI via a service module.
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
/**
|
|
* ArtStation project importer CLI.
|
|
*
|
|
* Usage:
|
|
* npm run import:artstation -- --user jmartgraphix
|
|
* npm run import:artstation -- --user jmartgraphix --dry-run
|
|
* npm run import:artstation -- --url https://www.artstation.com/artwork/XXXX
|
|
* npm run import:artstation -- --user jmartgraphix --publish
|
|
*
|
|
* Prefer the Admin → Dashboard “Import from ArtStation” button in production.
|
|
*/
|
|
import "dotenv/config";
|
|
import { runArtStationImport } from "../src/services/artstation-import.js";
|
|
import { prisma } from "../src/lib/prisma.js";
|
|
|
|
function arg(name: string, fallback?: string): string | undefined {
|
|
const idx = process.argv.indexOf(`--${name}`);
|
|
if (idx >= 0 && process.argv[idx + 1]) return process.argv[idx + 1];
|
|
return fallback;
|
|
}
|
|
|
|
function hasFlag(name: string): boolean {
|
|
return process.argv.includes(`--${name}`);
|
|
}
|
|
|
|
async function main() {
|
|
const result = await runArtStationImport({
|
|
username: arg("user", "jmartgraphix"),
|
|
url: arg("url"),
|
|
dryRun: hasFlag("dry-run"),
|
|
publish: hasFlag("publish"),
|
|
});
|
|
console.log(
|
|
`Summary: found=${result.found} imported=${result.imported} skipped=${result.skipped} errors=${result.errors}`
|
|
);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(() => prisma.$disconnect());
|