forked from pkreissel/foryoufeed
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pkreissel#6 from pkreissel/recommender
Recommender
- Loading branch information
Showing
69 changed files
with
3,949 additions
and
1,383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
coverage | ||
.env | ||
.env | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import { mastodon } from "masto"; | ||
export default function getReblogsFeature(api: mastodon.rest.Client): Promise<any>; | ||
export default function getReblogsFeature(api: mastodon.rest.Client): Promise<Record<string, number>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import { mastodon } from "masto"; | ||
export default function getHomeFeed(api: mastodon.rest.Client, user: mastodon.v1.Account): Promise<any[]>; | ||
import { StatusType } from "../types"; | ||
export default function getHomeFeed(api: mastodon.rest.Client, _user: mastodon.v1.Account): Promise<StatusType[]>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { mastodon } from "masto"; | ||
import { StatusType } from "../types"; | ||
export default function getRecommenderFeed(_api: mastodon.rest.Client, _user: mastodon.v1.Account): Promise<StatusType[]>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const change_case_1 = require("change-case"); | ||
const helpers_1 = require("../helpers"); | ||
async function getRecommenderFeed(_api, _user) { | ||
let data, res; | ||
try { | ||
res = await fetch("http://127.0.0.1:5000"); | ||
data = await res.json(); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
return []; | ||
} | ||
if (!res.ok) { | ||
return []; | ||
} | ||
const statuses = data.statuses.map((status) => { | ||
status.recommended = true; | ||
return status; | ||
}); | ||
return (0, helpers_1._transformKeys)(statuses, change_case_1.camelCase); | ||
} | ||
exports.default = getRecommenderFeed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import { mastodon } from "masto"; | ||
export default function getTopPostFeed(api: mastodon.rest.Client): Promise<mastodon.v1.Status[]>; | ||
import { StatusType } from "../types"; | ||
export default function getTopPostFeed(api: mastodon.rest.Client): Promise<StatusType[]>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export declare const isRecord: (x: unknown) => x is Record<string, unknown>; | ||
export declare const _transformKeys: <T>(data: T, transform: (key: string) => string) => T; | ||
export declare const mastodonFetch: <T>(server: string, endpoint: string) => Promise<T | undefined>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mastodonFetch = exports._transformKeys = exports.isRecord = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
const change_case_1 = require("change-case"); | ||
//Masto does not support top posts from foreign servers, so we have to do it manually | ||
const isRecord = (x) => typeof x === "object" && x !== null && x.constructor.name === "Object"; | ||
exports.isRecord = isRecord; | ||
const _transformKeys = (data, transform) => { | ||
if (Array.isArray(data)) { | ||
return data.map((value) => (0, exports._transformKeys)(value, transform)); | ||
} | ||
if ((0, exports.isRecord)(data)) { | ||
return Object.fromEntries(Object.entries(data).map(([key, value]) => [ | ||
transform(key), | ||
(0, exports._transformKeys)(value, transform), | ||
])); | ||
} | ||
return data; | ||
}; | ||
exports._transformKeys = _transformKeys; | ||
const mastodonFetch = async (server, endpoint) => { | ||
const json = await axios_1.default.get(`https://${server}${endpoint}`); | ||
if (!(json.status === 200) || !json.data) { | ||
console.error(`Error fetching data for server ${server}:`, json); | ||
return; | ||
} | ||
const data = (0, exports._transformKeys)(json.data, change_case_1.camelCase); | ||
return data; | ||
}; | ||
exports.mastodonFetch = mastodonFetch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.