feat: IMVU imports on the hub: grants, requests and the importer's job queue
Creators grant a catalog leave to import their IMVU products (whole shop less exclusions, or listed products) from a linked IMVU account, agreeing to a versioned consent text; the catalog's team accepts or declines. Requests queue covered products (or add them to the library when imported already), suggest, or count. Importers claim jobs with the catalog's importer key, get t5de-import tokens, and the catalog registers imported revisions as published products owned by the creator. Narrowing or withdrawing a grant withdraws products; unlinking suspends grants; an hourly batch rechecks imported products with IMVU daily. Website: /imports and the console's catalog imports page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
eca1884918
commit
7d708aebdb
24 files changed
+6521
-153
No files matched your search
@@ -0,0 +1,76 @@
|
||||
CREATE TABLE "import_grant" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"catalog_id" text NOT NULL,
|
||||
"creator_id" text NOT NULL,
|
||||
"imvu_id" bigint NOT NULL,
|
||||
"scope" text NOT NULL,
|
||||
"products" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||
"exclude" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||
"listed" boolean DEFAULT true NOT NULL,
|
||||
"consent_version" integer NOT NULL,
|
||||
"consented_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"consent_kind" text DEFAULT 'verified' NOT NULL,
|
||||
"evidence" text DEFAULT '' NOT NULL,
|
||||
"recorded_by" text,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"status_reason" text DEFAULT '' NOT NULL,
|
||||
"decided_at" timestamp with time zone,
|
||||
"decided_by" text,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "import_job" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"catalog_id" text NOT NULL,
|
||||
"grant_id" text NOT NULL,
|
||||
"imvu_product" bigint NOT NULL,
|
||||
"kind" text NOT NULL,
|
||||
"status" text DEFAULT 'queued' NOT NULL,
|
||||
"imvu_revision" integer,
|
||||
"reason" text DEFAULT '' NOT NULL,
|
||||
"attempts" integer DEFAULT 0 NOT NULL,
|
||||
"claimed_at" timestamp with time zone,
|
||||
"next_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "import_request" (
|
||||
"user_id" text NOT NULL,
|
||||
"imvu_creator" bigint NOT NULL,
|
||||
"imvu_product" bigint NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"fulfilled_at" timestamp with time zone,
|
||||
CONSTRAINT "import_request_user_id_imvu_creator_imvu_product_pk" PRIMARY KEY("user_id","imvu_creator","imvu_product")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "imvu_product_info" (
|
||||
"id" bigint PRIMARY KEY NOT NULL,
|
||||
"found" boolean NOT NULL,
|
||||
"name" text DEFAULT '' NOT NULL,
|
||||
"creator_id" bigint DEFAULT 0 NOT NULL,
|
||||
"creator_name" text DEFAULT '' NOT NULL,
|
||||
"rating" text DEFAULT 'general' NOT NULL,
|
||||
"purchasable" boolean DEFAULT true NOT NULL,
|
||||
"checked_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "catalog" ADD COLUMN "importer" text DEFAULT 'off' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "catalog" ADD COLUMN "importer_key_hash" text;--> statement-breakpoint
|
||||
ALTER TABLE "product" ADD COLUMN "imvu_product" bigint;--> statement-breakpoint
|
||||
ALTER TABLE "product_revision" ADD COLUMN "imvu_revision" integer;--> statement-breakpoint
|
||||
ALTER TABLE "import_grant" ADD CONSTRAINT "import_grant_catalog_id_catalog_id_fk" FOREIGN KEY ("catalog_id") REFERENCES "public"."catalog"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "import_grant" ADD CONSTRAINT "import_grant_creator_id_user_id_fk" FOREIGN KEY ("creator_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "import_grant" ADD CONSTRAINT "import_grant_recorded_by_user_id_fk" FOREIGN KEY ("recorded_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "import_grant" ADD CONSTRAINT "import_grant_decided_by_user_id_fk" FOREIGN KEY ("decided_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "import_job" ADD CONSTRAINT "import_job_catalog_id_catalog_id_fk" FOREIGN KEY ("catalog_id") REFERENCES "public"."catalog"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "import_job" ADD CONSTRAINT "import_job_grant_id_import_grant_id_fk" FOREIGN KEY ("grant_id") REFERENCES "public"."import_grant"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "import_request" ADD CONSTRAINT "import_request_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "import_grant_catalog" ON "import_grant" USING btree ("catalog_id","status");--> statement-breakpoint
|
||||
CREATE INDEX "import_grant_imvu" ON "import_grant" USING btree ("imvu_id","status");--> statement-breakpoint
|
||||
CREATE INDEX "import_job_queue" ON "import_job" USING btree ("catalog_id","status","next_at");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "import_job_open" ON "import_job" USING btree ("catalog_id","imvu_product") WHERE "import_job"."status" in ('queued', 'claimed');--> statement-breakpoint
|
||||
CREATE INDEX "import_request_creator" ON "import_request" USING btree ("imvu_creator");--> statement-breakpoint
|
||||
CREATE INDEX "import_request_product" ON "import_request" USING btree ("imvu_product");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "product_imvu_product" ON "product" USING btree ("imvu_product");
|
||||
File diff suppressed because it is too large.
Load diff
@@ -113,6 +113,13 @@
|
||||
"when": 1793934143730,
|
||||
"tag": "0015_two_factor",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 16,
|
||||
"version": "7",
|
||||
"when": 1793935614967,
|
||||
"tag": "0016_imports",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -289,6 +289,9 @@ export const catalog = pgTable(
|
||||
uploads: text("uploads").notNull().default("anyone"), // who may upload: "anyone", "members", "team"
|
||||
mirrors: text("mirrors").notNull().default("approve"), // mirroring others' revisions: "auto", "approve", "off"
|
||||
keyHash: text("key_hash").notNull(), // sha256 of its key, hex
|
||||
// Imports (docs/imports.md): "off", "on" or "paused" (the hub hands its importer no jobs); the importer's key.
|
||||
importer: text("importer").notNull().default("off"),
|
||||
importerKeyHash: text("importer_key_hash"), // sha256, hex
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
},
|
||||
@@ -393,10 +396,13 @@ export const product = pgTable(
|
||||
// Removed by moderation: gone everywhere (no page, no files, out of libraries and rooms).
|
||||
removedAt: timestamp("removed_at", { withTimezone: true }),
|
||||
removedReason: text("removed_reason"),
|
||||
// Imported from IMVU (docs/imports.md): the IMVU product, one hub product each.
|
||||
imvuProduct: bigint("imvu_product", { mode: "number" }),
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
},
|
||||
(t) => [
|
||||
uniqueIndex("product_imvu_product").on(t.imvuProduct),
|
||||
index("product_creator").on(t.creatorId),
|
||||
index("product_created").on(t.createdAt),
|
||||
index("product_tags").using("gin", t.tags),
|
||||
@@ -440,6 +446,7 @@ export const productRevision = pgTable(
|
||||
token: text("token").notNull(), // the hub's t5de-revision token
|
||||
uploadedBy: text("uploaded_by").references(() => user.id, { onDelete: "set null" }),
|
||||
retracted: boolean("retracted").notNull().default(false),
|
||||
imvuRevision: integer("imvu_revision"), // imported: the IMVU revision it came from
|
||||
createdAt: createdAt(),
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.productId, t.number] }), index("product_revision_files").using("gin", t.files)],
|
||||
@@ -708,3 +715,99 @@ export const apiToken = pgTable(
|
||||
},
|
||||
(t) => [uniqueIndex("api_token_hash").on(t.hash), index("api_token_user").on(t.userId)],
|
||||
);
|
||||
|
||||
// ---- imports (docs/imports.md) ----
|
||||
|
||||
// A creator's consent for one catalog to import their IMVU products: the whole shop (less exclusions) or listed ones.
|
||||
export const importGrant = pgTable(
|
||||
"import_grant",
|
||||
{
|
||||
id: text("id").primaryKey(),
|
||||
catalogId: text("catalog_id")
|
||||
.notNull()
|
||||
.references(() => catalog.id, { onDelete: "cascade" }),
|
||||
creatorId: text("creator_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
imvuId: bigint("imvu_id", { mode: "number" }).notNull(), // the IMVU account whose products these are
|
||||
scope: text("scope").notNull(), // "shop", "products"
|
||||
products: jsonb("products").$type<number[]>().notNull().default([]), // scope "products": the IMVU product IDs
|
||||
exclude: jsonb("exclude").$type<number[]>().notNull().default([]), // scope "shop": left out
|
||||
listed: boolean("listed").notNull().default(true), // imported products are listed
|
||||
consentVersion: integer("consent_version").notNull(),
|
||||
consentedAt: timestamp("consented_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
consentKind: text("consent_kind").notNull().default("verified"), // "verified" (the creator), "recorded" (an admin)
|
||||
evidence: text("evidence").notNull().default(""), // recorded: how they agreed
|
||||
recordedBy: text("recorded_by").references(() => user.id, { onDelete: "set null" }),
|
||||
// "pending" (the catalog's team hasn't accepted), "active", "declined", "suspended", "withdrawn".
|
||||
status: text("status").notNull().default("pending"),
|
||||
statusReason: text("status_reason").notNull().default(""),
|
||||
decidedAt: timestamp("decided_at", { withTimezone: true }),
|
||||
decidedBy: text("decided_by").references(() => user.id, { onDelete: "set null" }),
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
},
|
||||
(t) => [index("import_grant_catalog").on(t.catalogId, t.status), index("import_grant_imvu").on(t.imvuId, t.status)],
|
||||
);
|
||||
|
||||
// Someone asking for an IMVU product (or, with imvuProduct 0, a creator's whole shop) on T5DE. One per person and target.
|
||||
export const importRequest = pgTable(
|
||||
"import_request",
|
||||
{
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
imvuCreator: bigint("imvu_creator", { mode: "number" }).notNull(),
|
||||
imvuProduct: bigint("imvu_product", { mode: "number" }).notNull(), // 0: the whole shop
|
||||
createdAt: createdAt(),
|
||||
fulfilledAt: timestamp("fulfilled_at", { withTimezone: true }), // the product reached their library
|
||||
},
|
||||
(t) => [
|
||||
primaryKey({ columns: [t.userId, t.imvuCreator, t.imvuProduct] }),
|
||||
index("import_request_creator").on(t.imvuCreator),
|
||||
index("import_request_product").on(t.imvuProduct),
|
||||
],
|
||||
);
|
||||
|
||||
// One product for a catalog's importer to import or re-check.
|
||||
export const importJob = pgTable(
|
||||
"import_job",
|
||||
{
|
||||
id: text("id").primaryKey(),
|
||||
catalogId: text("catalog_id")
|
||||
.notNull()
|
||||
.references(() => catalog.id, { onDelete: "cascade" }),
|
||||
grantId: text("grant_id")
|
||||
.notNull()
|
||||
.references(() => importGrant.id, { onDelete: "cascade" }),
|
||||
imvuProduct: bigint("imvu_product", { mode: "number" }).notNull(),
|
||||
kind: text("kind").notNull(), // "import", "recheck"
|
||||
status: text("status").notNull().default("queued"), // "queued", "claimed", "done", "failed"
|
||||
imvuRevision: integer("imvu_revision"), // done: the revision imported (or found unchanged)
|
||||
reason: text("reason").notNull().default(""), // why it failed (last attempt)
|
||||
attempts: integer("attempts").notNull().default(0),
|
||||
claimedAt: timestamp("claimed_at", { withTimezone: true }),
|
||||
nextAt: timestamp("next_at", { withTimezone: true }).notNull().defaultNow(), // queued: not before
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
},
|
||||
(t) => [
|
||||
index("import_job_queue").on(t.catalogId, t.status, t.nextAt),
|
||||
// One open job per product and catalog.
|
||||
uniqueIndex("import_job_open")
|
||||
.on(t.catalogId, t.imvuProduct)
|
||||
.where(sql`${t.status} in ('queued', 'claimed')`),
|
||||
],
|
||||
);
|
||||
|
||||
// IMVU products' public info, as imports and requests need it (looked up again after a day).
|
||||
export const imvuProductInfo = pgTable("imvu_product_info", {
|
||||
id: bigint("id", { mode: "number" }).primaryKey(),
|
||||
found: boolean("found").notNull(), // IMVU shows it publicly
|
||||
name: text("name").notNull().default(""),
|
||||
creatorId: bigint("creator_id", { mode: "number" }).notNull().default(0),
|
||||
creatorName: text("creator_name").notNull().default(""),
|
||||
rating: text("rating").notNull().default("general"), // "general", "adult" (IMVU's AP)
|
||||
purchasable: boolean("purchasable").notNull().default(true),
|
||||
checkedAt: timestamp("checked_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
Reference in new issue
Block a user