🤯 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: {
rest: "POST /flushDB",
params: {},
async handler(ctx: Context<{}>) {
handler: async (ctx: Context<{}>) => {
return await Comic.collection
.drop()
.then((data) => {
.then(async (data) => {
console.info(data);
const foo = fsExtra.emptyDirSync(
const coversFolderDeleteResult = fsExtra.emptyDirSync(
path.resolve(`${USERDATA_DIRECTORY}/covers`)
);
const foo2 = fsExtra.emptyDirSync(
const expandedFolderDeleteResult = fsExtra.emptyDirSync(
path.resolve(
`${USERDATA_DIRECTORY}/expanded`
)
);
return { data, foo, foo2 };
const eSIndicesDeleteResult = await ctx.broker.call("search.deleteElasticSearchIndices", {});
return { data, coversFolderDeleteResult, expandedFolderDeleteResult, eSIndicesDeleteResult };
})
.catch((error) => error);
},
},
unrarArchive: {
rest: "POST /unrarArchive",
params: {},

View File

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