Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static async getAuthClient(username: string, protocol: Protocol = 'http'): Promise {
let clients = protocol === 'http' ? this.authorizedHTTP : this.authorizedWebSocket
if (!clients.has(username)) {
// usernameからドメインをとトークンをデータベースから取得してクライアントを作る
let db = Datastore.create({
filename: join(app.getPath("userData"), "account.db"),
autoload: true
})
try {
let doc = await db.findOne<{ domain: string; accessToken: string; }>({ full: username })
Client.setAuthClient(protocol, username, Client.createAuthClient(protocol, doc.domain, doc.accessToken))
} catch (err) {
throw err
}
}
return clients.get(username)!
}
save: async (config) => {
const cfg = JSON.parse(JSON.stringify(config));
const datastore = Datastore.create(dbPath());
// do not store sensitive info
delete cfg.keys;
delete cfg.nodeKeys;
return datastore.insert(cfg);
},
const fs = require('fs');
const tempDirectory = require("temp-dir");
const runJob = require("./lib/runJob");
var app = require("express")();
var http = require("http").createServer(app);
var io = require("socket.io")(http);
const cors = require("cors");
const bodyParser = require("body-parser");
app.use(cors());
app.use(bodyParser.json());
let db = {};
db.runs = Datastore.create(`${tempDirectory}/wflow/data/runs.db`);
db.jobs = Datastore.create(`${tempDirectory}/wflow/data/jobs.db`);
db.steps = Datastore.create(`${tempDirectory}/wflow/data/steps.db`);
app.get('/', (req, res)=>{
res.send('Hello!');
});
app.post("/runs", async (req, res) => {
var workflow = req.body;
workflow.status = "incomplete";
var wRes = await db.runs.insert(workflow);
workflow._id = wRes._id;
for (let jobId in workflow.jobs) {
let job = workflow.jobs[jobId];
const tempDirectory = require("temp-dir");
const runJob = require("./lib/runJob");
var app = require("express")();
var http = require("http").createServer(app);
var io = require("socket.io")(http);
const cors = require("cors");
const bodyParser = require("body-parser");
app.use(cors());
app.use(bodyParser.json());
let db = {};
db.runs = Datastore.create(`${tempDirectory}/wflow/data/runs.db`);
db.jobs = Datastore.create(`${tempDirectory}/wflow/data/jobs.db`);
db.steps = Datastore.create(`${tempDirectory}/wflow/data/steps.db`);
app.get('/', (req, res)=>{
res.send('Hello!');
});
app.post("/runs", async (req, res) => {
var workflow = req.body;
workflow.status = "incomplete";
var wRes = await db.runs.insert(workflow);
workflow._id = wRes._id;
for (let jobId in workflow.jobs) {
let job = workflow.jobs[jobId];
var jRes = await db.jobs.insert({
return
}
if (tokenData.accessToken === undefined) {
let error = new Error("Failed to get access token.")
error.name = "ERROR_GET_TOKEN"
event.sender.send(`login-complete`, undefined, error)
return
}
const client = Client.createAuthClient('http', instance, tokenData.accessToken)
let resp: Response = await client.get("/accounts/verify_credentials")
let you = resp.data
let db = Datastore.create({
filename: join(app.getPath("userData"), "account.db"),
autoload: true
})
let docs: AccountDoc = {
domain: instance,
acct: you.acct,
full: you.acct + "@" + instance,
avatar: you.avatar,
avatarStatic: you.avatar_static,
accessToken: tokenData.accessToken,
}
try {
let newDoc = await db.insert(docs)
Client.setAuthClient('http', newDoc.full, client)
private static async onAddTimeline(event: Event, name: string, type: string) {
if (!(type in this.endpoints) && type !== 'no-auth') {
event.sender.send(`add-timeline`, undefined, new Error("Not supported type"))
return
}
let db = Datastore.create({
filename: join(app.getPath("userData"), "timeline.db"),
autoload: true
})
let docs: TimelineDoc = {
name: name,
type: type,
}
try {
let newDoc = await db.insert(docs)
event.sender.send(`add-timeline`, newDoc)
} catch (err) {
let error = new Error("Cannot save timeline.")
error.name = "ERROR_ADD_TIMELINE"
event.sender.send(`add-timeline`, undefined, error)
list: async (projection = {}) => {
const datastore = Datastore.create(dbPath());
return datastore.find({}, projection).sort({ name: 1 });
},
private static async getTimeline(id: string): Promise {
let db = Datastore.create({
filename: join(app.getPath("userData"), "timeline.db"),
autoload: true
})
try {
return db.findOne({ _id: id })
} catch (err) {
throw err
}
}