Fix globalResolve bad import

This commit is contained in:
Romaric Mourgues
2023-04-18 09:13:08 +02:00
parent 1f0f2b4a1f
commit 19030f7f72
14 changed files with 3 additions and 365 deletions
-4
View File
@@ -45,10 +45,6 @@ export default {
text: "Get started",
link: "/internal-documentation/backend-services/intro/README.md",
},
{
text: "Applications",
link: "/internal-documentation/backend-services/applications/README.md",
},
{
text: "Documents",
link: "/internal-documentation/backend-services/documents/README.md",
@@ -1,14 +0,0 @@
import { CommandModule } from "yargs";
const command: CommandModule = {
describe: "Manage Tdrive Applications",
command: "applications <command>",
builder: yargs =>
yargs.commandDir("applications_cmds", {
visit: commandModule => commandModule.default,
}),
// eslint-disable-next-line @typescript-eslint/no-empty-function
handler: () => {},
};
export default command;
@@ -1,14 +0,0 @@
import { CommandModule } from "yargs";
const command: CommandModule = {
describe: "Migrate your php message to node",
command: "migration <command>",
builder: yargs =>
yargs.commandDir("migration_cmds", {
visit: commandModule => commandModule.default,
}),
// eslint-disable-next-line @typescript-eslint/no-empty-function
handler: () => {},
};
export default command;
@@ -1,14 +0,0 @@
import { CommandModule } from "yargs";
const command: CommandModule = {
describe: "Manage Tdrive Workspaces",
command: "workspace <command>",
builder: yargs =>
yargs.commandDir("workspace_cmds", {
visit: commandModule => commandModule.default,
}),
// eslint-disable-next-line @typescript-eslint/no-empty-function
handler: () => {},
};
export default command;
@@ -1,47 +0,0 @@
import yargs from "yargs";
import ora from "ora";
import Table from "cli-table";
import tdrive from "../../../tdrive";
import gr from "../../../services/global-resolver";
/**
* Merge command parameters. Check the builder definition below for more details.
*/
type ListParams = {
size: string;
};
const services = [
"platform-services",
"user",
"search",
"channels",
"notifications",
"database",
"webserver",
"message-queue",
];
const command: yargs.CommandModule<ListParams, ListParams> = {
command: "list",
describe: "List Tdrive workspaces",
builder: {
size: {
default: "50",
type: "string",
description: "Number of workspaces to fetch",
},
},
handler: async argv => {
const table = new Table({ head: ["ID", "Name"], colWidths: [40, 50] });
const spinner = ora({ text: "List Tdrive workspaces" }).start();
const platform = await tdrive.run(services);
await gr.doInit(platform);
const workspaces = await gr.services.workspaces.list({ limitStr: argv.size });
spinner.stop();
workspaces.getEntities().forEach(ws => table.push([ws.id, ws.name]));
console.log(table.toString());
},
};
export default command;
@@ -1,49 +0,0 @@
import yargs from "yargs";
import ora from "ora";
import Table from "cli-table";
import tdrive from "../../../tdrive";
import gr from "../../../services/global-resolver";
/**
* Merge command parameters. Check the builder definition below for more details.
*/
type ListParams = {
id: string;
};
const services = [
"platform-services",
"user",
"search",
"channels",
"notifications",
"database",
"webserver",
"message-queue",
];
const command: yargs.CommandModule<ListParams, ListParams> = {
command: "user",
describe: "List workspace ers",
builder: {
id: {
default: "f339d54a-e833-11ea-92c3-0242ac120004",
type: "string",
description: "Workspace ID",
},
},
handler: async argv => {
const table = new Table({ head: ["user ID", "Date Added"], colWidths: [40, 40] });
const spinner = ora({ text: "Retrieving workspace users" }).start();
const platform = await tdrive.run(services);
await gr.doInit(platform);
const users = await gr.services.workspaces.getUsers({ workspaceId: argv.id });
spinner.stop();
users
.getEntities()
.forEach(u => table.push([u.id, new Date(u.dateAdded).toLocaleDateString()]));
console.log(table.toString());
},
};
export default command;
@@ -1,2 +0,0 @@
node_modules
yarn.lock
@@ -1,4 +0,0 @@
Edit the file to your needs
yarn install
node index.js
@@ -1,98 +0,0 @@
/* eslint-disable */
var cassandra = require("cassandra-driver");
var fromAuthProvider = new cassandra.auth.PlainTextAuthProvider("", "");
var fromContactPoints = [""];
var toAuthProvider = new cassandra.auth.PlainTextAuthProvider("", "");
var toContactPoints = [""];
// -- start process
var fromClient = new cassandra.Client({
localDataCenter: "datacenter1",
contactPoints: fromContactPoints,
authProvider: fromAuthProvider,
keyspace: "tdrive",
});
var toClient = new cassandra.Client({
localDataCenter: "datacenter1",
contactPoints: toContactPoints,
authProvider: toAuthProvider,
keyspace: "tdrive",
queryOptions: {
consistency: cassandra.types.consistencies.quorum,
},
});
// -- Get all tables and copy schema
async function client(origin, query, parameters, options) {
return await new Promise((resolve, reject) => {
origin.execute(query, [], {}, function (err, result) {
if (err) {
reject({ err, result });
} else {
resolve(result);
}
});
});
}
// Get all threads and then copy all messages in each threads
let copiedMessages = 0;
let copiedThreads = 0;
(async () => {
await new Promise(r => {
fromClient.eachRow(
"SELECT id from tdrive.threads",
[],
{ prepare: true, fetchSize: 50 },
async function (n, row) {
const threadId = row["id"];
console.log("Threads / Messages :", copiedThreads, "/", copiedMessages);
copiedThreads++;
await new Promise(r2 => {
fromClient.eachRow(
"SELECT JSON * from tdrive.messages where thread_id = ? order by id desc",
[threadId],
{ prepare: true, fetchSize: 1000 },
async function (n, row) {
const message = row["[json]"];
copiedMessages++;
await toClient.execute(
"INSERT INTO tdrive.messages JSON '" + message.replace(/'/g, "'$&") + "'",
[],
{ prepare: true },
);
},
async function (err, result) {
if (result && result.nextPage) {
await new Promise(r => setTimeout(r, 100));
result.nextPage();
} else {
r2();
}
},
);
});
},
async function (err, result) {
if (result && result.nextPage) {
await new Promise(r => setTimeout(r, 2000));
result.nextPage();
} else {
r();
}
},
);
});
})();
@@ -1,9 +0,0 @@
{
"name": "copy-messages",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"cassandra-driver": "^4.6.3"
}
}
@@ -1,4 +0,0 @@
Edit the file to your needs
yarn install
node index.js
@@ -1,96 +0,0 @@
/* eslint-disable */
var cassandra = require("cassandra-driver");
var authProvider = new cassandra.auth.PlainTextAuthProvider("", "");
var contactPoints = [""];
var client = new cassandra.Client({
localDataCenter: "datacenter1",
contactPoints: contactPoints,
authProvider: authProvider,
keyspace: "tdrive",
});
var threadsTable = "threads";
var messagesTable = "messages";
//Copy object to other table
(async () => {
const query = "SELECT * FROM " + threadsTable + " where answers>1000 allow filtering";
const parameters = [];
const options = { prepare: true, fetchSize: 1000 };
let count = 0;
let threads = {};
await new Promise(r => {
client.eachRow(
query,
parameters,
options,
function (n, row) {
threads[row.id] ||= { answers: 0, id: row.id };
count++;
},
function (err, result) {
if (result && result.nextPage) {
result.nextPage();
} else {
r();
}
},
);
});
console.log(
"Downloaded ",
Object.keys(threads).length,
" threads of ",
messagesTable,
". Starting copy...",
);
for (var key of Object.keys(threads)) {
await new Promise(r => {
const query = "SELECT id FROM " + messagesTable + " where thread_id=" + key;
const parameters = [];
const options = { prepare: true, fetchSize: 1000 };
client.eachRow(
query,
parameters,
options,
function (n, row) {
threads[key].answers++;
},
function (err, result) {
if (result && result.nextPage) {
result.nextPage();
} else {
r();
}
},
);
r();
});
}
var copyCount = 0;
for (var key of Object.keys(threads)) {
copyCount++;
if (copyCount % 100 == 0) {
console.log(copyCount, "of", Object.keys(threads));
}
const row = threads[key];
await new Promise(r => {
let query = "UPDATE " + threadsTable + " SET answers=? WHERE id=?";
console.log(query, [row.answers, row.id + ""]);
//client.execute(query, [row.answers, row.id], () => {
// r();
//});
});
}
console.log("Ended with ", Object.keys(threads), "threads");
})();
@@ -1,9 +0,0 @@
{
"name": "repair-threads",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"cassandra-driver": "^4.6.3"
}
}
@@ -3,6 +3,8 @@ import WebServerAPI from "../../core/platform/services/webserver/provider";
import web from "./web/index";
import FastProxy from "fast-proxy";
import globalResolver from "../global-resolver";
import config from "config";
import Application from "../applications/entities/application";
@Prefix("/api")
export default class ApplicationsApiService extends TdriveService<undefined> {
@@ -17,7 +19,7 @@ export default class ApplicationsApiService extends TdriveService<undefined> {
});
//Redirect requests from /plugins/* to the plugin server (if installed)
const apps = await globalResolver.services.applications.marketplaceApps.list(null);
const apps = config.get<Application[]>("applications.plugins") || [];
for (const app of apps) {
const domain = app.internal_domain;
const prefix = app.external_prefix;