Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async connect(truncate) {
this.client = new elasticsearch.Client({
node: 'http://localhost:9200',
compression: true
});
try {
await this.client.ping()
if (await this.client.indices.exists({
index: ["site", "feed", "op_file"]
}) && (!truncate))
signale.debug("Indices exist")
else {
await this.client.indices.delete({
index: "*" // Clear broken indices
})
signale.debug("Deleted all indices")
await this.client.indices.create({ // Difference between original names and these: '_' instead of '-'
index: "site",
body: {
"mappings": {
"properties": {
"address": { "type": "keyword" },
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
this.watchConfigs((event, path) => {
signale.debug(`[${event}] ${path}`);
try {
const newConfig = this.getConfig({
force: true,
setConfig: newConfig => {
this.config = newConfig;
},
});
// 从失败中恢复过来,需要 reload 一次
if (this.configFailed) {
this.configFailed = false;
this.service.refreshBrowser();
}
const oldConfig = cloneDeep(this.config);
this.config = newConfig;
async connect(truncate) {
this.client = new elasticsearch.Client({
node: 'http://localhost:9200',
compression: true
});
try {
await this.client.ping()
if (await this.client.indices.exists({
index: ["site", "feed", "op_file"]
}) && (!truncate))
signale.debug("Indices exist")
else {
await this.client.indices.delete({
index: "*" // Clear broken indices
})
signale.debug("Deleted all indices")
await this.client.indices.create({ // Difference between original names and these: '_' instead of '-'
index: "site",
body: {
"mappings": {
"properties": {
"address": { "type": "keyword" },
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"files_number": { "type": "short" },
"op_files_number": { "type": "short" },
"domain": {
"type": "text",
"analyzer": "ik_max_word",
destroy(client) {
debug('destroy')
client.destroy();
}
};
apis.map((api, index) => {
const tokenName = api.name ? `${api.name.toUpperCase().replace(/-/g, '_')}_TOKEN` : null;
signale.debug(tokenName);
if (tokenName || isPlayerMode) {
const apiToken = processEnv[tokenName];
apis[index].token = isPlayerMode ? 'webMynaPlayerToken' : apiToken;
}
});
function getCharSet(headers) {
let charSet = 'UTF-8'
try {
charSet = /charset=(.*)/.exec(headers['content-type'])[1]
} catch (err) {
signale.debug('Error parsing charset', headers)
}
return charSet
}
connect() {
let uri = `ws${this.secureWs ? "s" : ""}://${this.zeroNetHost}/Websocket?wrapper_key=${this.wrapper_key}`
signale.debug(uri)
this.ws.connect(uri, null, null, null, {})
}
client.on("close", () => {
debug("连接关闭");
pool.release(client);
});
client.on("timeout", () => {