mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-22 09:37:17 +00:00
Update Algolia on report flag
This commit is contained in:
parent
54402d6cef
commit
80e2afe094
3 changed files with 16 additions and 6 deletions
5
packages/skin-database/algolia.ts
Normal file
5
packages/skin-database/algolia.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import algoliasearch from "algoliasearch";
|
||||
import { ALGOLIA_INDEX, ALGOLIA_KEY } from "./config";
|
||||
|
||||
const client = algoliasearch(ALGOLIA_INDEX, ALGOLIA_KEY);
|
||||
export const searchIndex = client.initIndex("Skins");
|
||||
|
|
@ -2,6 +2,7 @@ import db from "../db";
|
|||
import path from "path";
|
||||
import S3 from "../s3";
|
||||
import logger from "../logger";
|
||||
import { searchIndex } from "../algolia";
|
||||
import { DBSkinRecord, SkinRecord, DBIARecord, TweetStatus } from "../types";
|
||||
import fetch from "node-fetch";
|
||||
import { analyseBuffer, NsfwPrediction } from "../nsfwImage";
|
||||
|
|
@ -206,6 +207,14 @@ export async function markAsTweeted(md5: string): Promise<void> {
|
|||
|
||||
export async function markAsNSFW(md5: string): Promise<void> {
|
||||
await skins.findOneAndUpdate({ md5 }, { $set: { nsfw: true } });
|
||||
const indexes = [{ objectID: md5, nsfw: true }];
|
||||
// TODO: Await here, but for some reason this never completes
|
||||
new Promise((resolve, reject) => {
|
||||
searchIndex.partialUpdateObjects(indexes, function (err, content) {
|
||||
if (err != null) reject(err);
|
||||
resolve(content);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function getStatus(md5: string): Promise<TweetStatus> {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
const algoliasearch = require("algoliasearch");
|
||||
const { ALGOLIA_INDEX, ALGOLIA_KEY } = require("../config");
|
||||
const { searchIndex } = require("../algolia");
|
||||
const path = require("path");
|
||||
const db = require("../db");
|
||||
|
||||
const client = algoliasearch(ALGOLIA_INDEX, ALGOLIA_KEY);
|
||||
const index = client.initIndex("Skins");
|
||||
|
||||
function tuncate(str, len) {
|
||||
const overflow = str.length - len;
|
||||
if (overflow < 0) {
|
||||
|
|
@ -65,7 +61,7 @@ async function go({ dry = true }) {
|
|||
}
|
||||
console.log("Writing index");
|
||||
const results = await new Promise((resolve, reject) => {
|
||||
index.partialUpdateObjects(indexes, function (err, content) {
|
||||
searchIndex.partialUpdateObjects(indexes, function (err, content) {
|
||||
if (err != null) reject(err);
|
||||
resolve(content);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue