export const getOrphanedFiles = internalQuery({
args: {},
handler: async (ctx) => {
const ONE_HOUR_MS = 1000 * 60 * 60;
const cutoffTimeMs = Date.now() - ONE_HOUR_MS;
const orphanedFiles = await ctx.db
.query("files")
.withIndex("by_is_uploaded_created_at", q =>
q.eq("isUploaded", false).lte("createdAt", cutoffTimeMs)
)
.withIndex("by_article_id", q =>
q.eq("articleId", undefined)
)
.take(100);
return orphanedFiles;
},
});
files: defineTable({
articleId: v.optional(v.id("articles")),
name: v.string(),
contentType: v.string(),
sizeBytes: v.number(),
isPrivate: v.boolean(),
isUploaded: v.boolean(),
createdAt: v.number(),
updatedAt: v.number(),
})
.index("by_is_uploaded_created_at", ["isUploaded", "createdAt"])
.index("by_article_id", ["articleId"]),
Property 'withIndex' does not exist on type 'Query<{ document: { _id: Id<"files">; _creationTime: number; articleId?: Id<"articles"> | undefined; createdAt: number; updatedAt: number; name: string; contentType: string; sizeBytes: number; isPrivate: boolean; isUploaded: boolean; }; fieldPaths: ExtractFieldPaths<...> | "_id"; indexes: { ...; }; searchIndexes: {}...'.ts(2339)