Remove old code

This commit is contained in:
Shadowfacts 2019-08-17 15:29:20 -04:00
parent 85e9f19a63
commit ed2a06f5bb
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
6 changed files with 1 additions and 170 deletions

View File

@ -40,14 +40,6 @@ export async function setup(posts: Page[]) {
article.conversation = articleObject.conversation;
article.hasFederated = false;
await getConnection().manager.save(article);
//db.run("INSERT OR IGNORE INTO articles(id, article_doc, conversation, has_federated) VALUES($id, $article_doc, $conversation, $has_federated)", {
//$id: postMeta.permalink,
//$article_doc: JSON.stringify(articleObject),
//$conversation: articleObject.conversation,
//$has_federated: 0
//}, (err) => {
//if (err) console.log(`Encountered error inserting article ${postMeta.permalink}`, err);
//});
}
}
@ -60,18 +52,6 @@ export async function toFederate(): Promise<[string, ArticleObject][]> {
result.push([it.id, it.articleObject]);
});
resolve(result);
//db.all("SELECT id, article_doc FROM articles WHERE has_federated = $has_federated", {
//$has_federated: 0
//}, (err, rows) => {
//if (err) reject(err);
//else {
//let result: [string, Article][] = [];
//for (const row of rows) {
//result.push([row.id, JSON.parse(row.article_doc)]);
//}
//resolve(result);
//}
//});
});
}
@ -91,17 +71,6 @@ export function route(router: Router) {
res.status(500).end(err);
}
//const db = <Database>req.app.get("db")
//db.get("SELECT article_doc FROM articles WHERE id = $id", {
//$id: `/${req.params.category}/${req.params.year}/${req.params.slug}/`
//}, (err, result) => {
//if (err) {
//res.status(500).end(err);
//return;
//}
//res.type("application/activity+json");
//res.end(result.article_doc);
//});
} else {
res.status(415).end("No acceptable content-type given. text/html or application/activity+json are supported");
}

View File

@ -35,30 +35,6 @@ async function getConversationComments(conversation: string): Promise<Comment[]>
console.log("Couldn't load comments: ", err);
return [];
}
//return new Promise((resolve, reject) => {
//db.all("SELECT notes.id AS comment_id, notes.content, notes.published, notes.in_reply_to, actors.id AS actor_id, actors.display_name, actors.icon_url FROM notes INNER JOIN actors ON actors.id = notes.attributed_to WHERE notes.conversation = $conversation", {
//$conversation: conversation
//}, (err, rows) => {
//if (err) {
//reject(err);
//} else {
//const comments = rows.map(row => {
//return {
//id: row.comment_id,
//content: row.content,
//published: row.published,
//inReplyTo: row.in_reply_to,
//author: {
//id: row.actor_id,
//name: row.display_name,
//icon: row.icon_url
//} as ActorObject
//} as Comment;
//});
//resolve(comments);
//}
//})
//});
}
export default function comments(router: Router) {
@ -81,15 +57,5 @@ export default function comments(router: Router) {
console.error("Couldn't retrieve conversation: ", err);
res.json([]).end();
}
//db.get("SELECT conversation FROM articles WHERE id = $id", {
//$id: id
//}, async (err, result) => {
//if (!result || !result.conversation) {
//res.json([]).end();
//return;
//}
//const comments = await getConversationComments(result.conversation, db);
//res.json(comments).end();
//});
});
}

View File

@ -56,29 +56,6 @@ export async function getCachedActor(url: string): Promise<ActorObject | null> {
} else {
return null;
}
//return new Promise(async (resolve, reject) => {
//db.get("SELECT * FROM actors WHERE id = $id", {
//$id: url
//}, (err, result) => {
//if (err) {
//reject(err);
//} else {
//if (result) {
//resolve({
//id: result.id,
//name: result.display_name,
//inbox: result.inbox,
//icon: result.icon_url,
//publicKey: {
//publicKeyPem: result.public_key_pem
//}
//} as ActorObject);
//} else {
//resolve(null);
//}
//}
//});
//});
}
async function cacheActor(actorObject: ActorObject) {
@ -95,15 +72,6 @@ async function cacheActor(actorObject: ActorObject) {
actor.publicKeyPem = actorObject.publicKey.publicKeyPem;
actor.isFollower = false;
await getConnection().manager.save(actor);
//db.run("INSERT OR REPLACE INTO actors(id, display_name, inbox, icon_url, public_key_pem) VALUES($id, $display_name, $inbox, $icon_url, $public_key_pem)", {
//$id: actor.id,
//$display_name: actor.name,
//$inbox: actor.inbox,
//$icon_url: iconURL,
//$public_key_pem: actor.publicKey.publicKeyPem
//}, (err) => {
//if (err) console.error(`Encountered error caching actor ${actor.id}`, err);
//});
}
async function fetchActor(url: string): Promise<ActorObject | null> {
@ -163,19 +131,6 @@ async function sendToFollowers(activity: CreateActivity) {
console.log(`Federating ${activity.object.id} to ${inbox}`);
signAndSend(activity, inbox);
});
//db.all("SELECT inbox FROM followers", (err, results) => {
//if (err) {
//console.log("Error getting followers: ", err);
//return;
//}
//const inboxes = results.map(it => "https://" + new URL(it.inbox).host + "/inbox");
//// convert to a Set to deduplicate inboxes
//(new Set(inboxes))
//.forEach(inbox => {
//console.log(`Federating ${activity.object.id} to ${inbox}`);
//signAndSend(activity, inbox);
//});
//});
}
export default async function federate(toFederate: [string, ArticleObject][]) {
@ -183,10 +138,6 @@ export default async function federate(toFederate: [string, ArticleObject][]) {
sendToFollowers(createActivity(article));
await getConnection().manager.update(Article, id, { hasFederated: true });
//db.run("UPDATE articles SET has_federated = 1 WHERE id = $id", {
//$id: id
//});
//break;
}
}

View File

@ -63,12 +63,6 @@ async function handleFollow(activity: Activity, req: Request, res: Response) {
.set({ isFollower: true })
.where("id = :id", { id: actor.id })
.execute();
//db.run("INSERT OR IGNORE INTO followers(id, inbox) VALUES($id, $inbox)", {
//$id: actor.id,
//$inbox: serverInbox
//}, (err) => {
//if (err) console.error(`Encountered error adding follower ${follow.actor}`, err);
//});
res.end();
}
@ -112,17 +106,6 @@ async function handleCreateNote(create: CreateActivity, req: Request, res: Respo
console.error(`Encountered error storing reply ${noteObject.id}`, err);
}
res.end();
//db.run("INSERT OR IGNORE INTO notes(id, content, attributed_to, in_reply_to, conversation, published) VALUES($id, $content, $attributed_to, $in_reply_to, $conversation, $published)", {
//$id: noteObject.id,
//$content: sanitizedContent,
//$attributed_to: noteObject.attributedTo,
//$in_reply_to: noteObject.inReplyTo,
//$conversation: noteObject.conversation,
//$published: noteObject.published
//}, (err) => {
//if (err) console.error(`Encountered error storing reply ${noteObject.id}`, err);
//res.end();
//});
}
async function handleDelete(activity: Activity, req: Request, res: Response) {
@ -138,14 +121,6 @@ async function handleDelete(activity: Activity, req: Request, res: Response) {
console.error(`Encountered error deleting ${deleteActivity.object}`, err);
}
res.end();
//const db = req.app.get("db") as Database;
//db.run("DELETE FROM notes WHERE id = $id, actor = $actor", {
//$id: deleteActivity.object,
//$actor: deleteActivity.actor
//}, (err) => {
//if (err) console.error(`Encountered error deleting ${deleteActivity.object}`, err);
//res.end();
//})
}
async function handleUndo(activity: Activity, req: Request, res: Response) {
@ -173,12 +148,4 @@ async function handleUndoFollow(undo: UndoActivity, req: Request, res: Response)
console.error(`Error handling unfollow from ${follow.actor}`, err);
}
res.end();
//const db = req.app.get("db") as Database;
//db.run("DELETE FROM followers WHERE id = $id", {
//$id: follow.actor
//}, (err) => {
//if (err) console.error(`Error unfollowing ${follow.actor}`, err);
//});
//res.end();
}

View File

@ -1,8 +1,6 @@
import crypto, { createVerify } from "crypto";
import crypto from "crypto";
import { Request, Response, NextFunction } from "express";
import { getActor } from "../federate";
import { IncomingHttpHeaders } from "http";
import { Database } from "sqlite3";
export = async (req: Request, res: Response, next: NextFunction) => {
if (req.method !== "POST") {

View File

@ -7,23 +7,10 @@ import bodyParser from "body-parser";
import activitypub from "./activitypub";
import validateHttpSig from "./activitypub/middleware/http-signature";
//import sqlite3 from "sqlite3";
import "reflect-metadata";
import { createConnection} from "typeorm";
import { promises as fs } from "fs";
import * as path from "path";
//createConnection().then(async connection => {
//}).catch(console.error);
//const db = new (sqlite3.verbose().Database)(process.env.DB_PATH!);
//db.run("CREATE TABLE IF NOT EXISTS followers (id TEXT PRIMARY KEY, inbox TEXT)");
//db.run("CREATE TABLE IF NOT EXISTS articles (id TEXT PRIMARY KEY, article_doc TEXT, conversation TEXT, has_federated INT)");
//db.run("CREATE TABLE IF NOT EXISTS notes (id TEXT PRIMARY KEY, content TEXT, attributed_to TEXT, in_reply_to TEXT, conversation TEXT, published TEXT)");
//db.run("CREATE TABLE IF NOT EXISTS actors (id TEXT PRIMARY KEY, display_name TEXT, inbox TEXT, icon_url TEXT, public_key_pem TEXT)")
async function generate(): Promise<Page[]> {
generators.copy();
generators.css();
@ -40,13 +27,6 @@ async function generate(): Promise<Page[]> {
return posts;
}
//const app = express();
//app.set("db", db);
//app.use(morgan("dev"));
//app.use(bodyParser.json({ type: "application/activity+json" }));
//db.run("DELETE FROM articles");
(async () => {
const app = express();
app.use(morgan("dev"));