🤯 Added a ES indice delete endpoint

This commit is contained in:
2022-04-04 22:56:34 -07:00
parent 1d295fcafc
commit 25d56e9249
2 changed files with 50 additions and 33 deletions

View File

@@ -547,25 +547,25 @@ export default class ImportService extends Service {
flushDB: { flushDB: {
rest: "POST /flushDB", rest: "POST /flushDB",
params: {}, params: {},
async handler(ctx: Context<{}>) { handler: async (ctx: Context<{}>) => {
return await Comic.collection return await Comic.collection
.drop() .drop()
.then((data) => { .then(async (data) => {
console.info(data); console.info(data);
const foo = fsExtra.emptyDirSync( const coversFolderDeleteResult = fsExtra.emptyDirSync(
path.resolve(`${USERDATA_DIRECTORY}/covers`) path.resolve(`${USERDATA_DIRECTORY}/covers`)
); );
const foo2 = fsExtra.emptyDirSync( const expandedFolderDeleteResult = fsExtra.emptyDirSync(
path.resolve( path.resolve(
`${USERDATA_DIRECTORY}/expanded` `${USERDATA_DIRECTORY}/expanded`
) )
); );
return { data, foo, foo2 }; const eSIndicesDeleteResult = await ctx.broker.call("search.deleteElasticSearchIndices", {});
return { data, coversFolderDeleteResult, expandedFolderDeleteResult, eSIndicesDeleteResult };
}) })
.catch((error) => error); .catch((error) => error);
}, },
}, },
unrarArchive: { unrarArchive: {
rest: "POST /unrarArchive", rest: "POST /unrarArchive",
params: {}, params: {},

View File

@@ -69,38 +69,55 @@ export default class SettingsService extends Service {
}; };
pagination: { pagination: {
size: number; size: number;
from: number, from: number;
}; };
}> }>
) => { ) => {
console.log(ctx.params); try {
const { query, pagination } = ctx.params; console.log(ctx.params);
let eSQuery = {}; const { query, pagination } = ctx.params;
if (isEmpty(query)) { let eSQuery = {};
Object.assign(eSQuery, { if (isEmpty(query)) {
match_all: {}, Object.assign(eSQuery, {
}); match_all: {},
} else { });
Object.assign(eSQuery, { } else {
multi_match: { Object.assign(eSQuery, {
fields: ["rawFileDetails.name", "sourcedMetadata.comicvine.name", "sourcedMetadata.comicvine.volumeInformation.name"], multi_match: {
query: query.volumeName, fields: [
"rawFileDetails.name",
"sourcedMetadata.comicvine.name",
"sourcedMetadata.comicvine.volumeInformation.name",
],
query: query.volumeName,
},
});
}
console.log(query);
const result = await eSClient.search(
{
index: "comics",
body: {
query: eSQuery,
},
...pagination,
}, },
}); { hydrate: true }
);
return result;
} catch (error) {
return new Errors.MoleculerClientError("Failed to return data", 404, "ElasticSearch error", error);
} }
console.log(query); },
const result = await eSClient.search( },
{ deleteElasticSearchIndices: {
index: "comics", rest: "GET /deleteElasticSearchIndices",
body: { params: {},
query: eSQuery, handler: async (ctx: Context<{}>) => {
}, return await eSClient.indices.delete({
...pagination, index: "comics",
}, });
{ hydrate: true }
);
return result;
}, },
}, },
}, },