Update Algolia on report flag

This commit is contained in:
Jordan Eldredge 2020-06-14 00:59:59 -04:00
parent 54402d6cef
commit 80e2afe094
3 changed files with 16 additions and 6 deletions

View 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");

View file

@ -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> {

View file

@ -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);
});