Skip to content

Commit

Permalink
Merge branch 'main' into project-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
shrivaths16 authored Dec 15, 2023
2 parents 7a74bfd + 99a5df6 commit ecd289d
Show file tree
Hide file tree
Showing 56 changed files with 415 additions and 453 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"no-var": [
"error"
],
"prefer-const": [
"error"
],
"@stylistic/arrow-spacing": [
"error",
{
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ build
npm-debug.log
.nyc
.env
.DS_Store
.DS_Store
.cursorignore
8 changes: 8 additions & 0 deletions admin/team-principles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Works on My Machine -- Team Code of Conduct
1. Be respectful towards your teammates at all times.
2. Attend meetings on a best-effort basis.
3. Give earliest possible notice when unable to attend a meeting, and read meeting minutes afterwards.
4. Check Slack at least once a day and be responsive to pings.
5. Respectful debate of design decisions is encouraged, but as a last resort, decisions will be arbitrated by a plurality vote.
6. Strive for quality over quantity of features at all times.
7. Proactively update GitHub issues whenever working on anything project-related.
2 changes: 1 addition & 1 deletion docs/Display.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Fetcher.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/InstanceEntry.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions docs/Paginator_Paginator.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="paginator.js.html">paginator.js</a>, <a href="paginator.js.html#line12">line 12</a>
<a href="paginator.js.html">paginator.js</a>, <a href="paginator.js.html#line10">line 10</a>
</li></ul></dd>


Expand Down Expand Up @@ -229,7 +229,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
8 changes: 2 additions & 6 deletions docs/entity_InstanceEntry.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,10 @@ <h1 class="page-title">Source: entity/InstanceEntry.js</h1>
&lt;/button>
&lt;/li>
`;
let script = document.createElement("script");
const script = document.createElement("script");
script.type = "module";
script.textContent = `
import { handleRemoveInstance } from './src/scripts/instanceList.js';
// document.getElementById('instance-removal-button').addEventListener('click', () => {
// handleRemoveInstance(${this.network}, ${this.url});
// console.log('removal button clicked');
// });
window.handleRemoveInstance = handleRemoveInstance;
`;
this.shadowRoot.appendChild(script);
Expand All @@ -111,7 +107,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions docs/fetchers_Fetcher.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="page-title">Source: fetchers/Fetcher.js</h1>
constructor() {
}

async fetchPosts(instanceUrl) {
async fetchPosts() {
throw new Error("Not implemented - You must implement fetchPosts() in a subclass");
}
}
Expand All @@ -54,7 +54,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
15 changes: 10 additions & 5 deletions docs/fetchers_LemmyFetcher.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ <h1 class="page-title">Source: fetchers/LemmyFetcher.js</h1>

<section>
<article>
<pre class="prettyprint source linenums"><code>import * as constant from "../entity/Constant.js";
import { Fetcher } from "./Fetcher.js";
<pre class="prettyprint source linenums"><code>import { Fetcher } from "./Fetcher.js";

const NUM_POSTS = 50;
const API_V3 = "/api/v3/post/list?sort=Hot";
Expand All @@ -41,11 +40,17 @@ <h1 class="page-title">Source: fetchers/LemmyFetcher.js</h1>
const posts = [];
try {
const url = instanceUrl + API_V3 + "&amp;limit=" + NUM_POSTS;
const response = await fetch(url);

const timeoutDelay = 10000;
const response = await Promise.race([
fetch(url),
new Promise((_resolve, reject) => setTimeout(() => reject("Fetch calls timed out."), timeoutDelay)),
]);

if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
let response_data = await response.json();
const response_data = await response.json();
const posts_json = response_data.posts;
posts_json.forEach((post) => {
posts.push(post);
Expand Down Expand Up @@ -74,7 +79,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
23 changes: 13 additions & 10 deletions docs/fetchers_MastodonFetcher.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ <h1 class="page-title">Source: fetchers/MastodonFetcher.js</h1>

<section>
<article>
<pre class="prettyprint source linenums"><code>import * as constant from "../entity/Constant.js";
import { Fetcher } from "./Fetcher.js";
<pre class="prettyprint source linenums"><code>import { Fetcher } from "./Fetcher.js";

export const TAGS_SUFFIX = "/api/v1/trends/tags";
export const POST_SUFFIX = "/api/v1/timelines/tag/:";
export const NUM_MASTODON_POSTS = 15;

export class MastodonFetcher extends Fetcher {
/**
Expand All @@ -40,12 +40,15 @@ <h1 class="page-title">Source: fetchers/MastodonFetcher.js</h1>
async fetchPosts(instURL) {
try {
const hashtags = await this.#fetchTrendingTags(instURL + TAGS_SUFFIX);
const posts = [];
for (const tag of hashtags) {
console.log("Fetching posts for tag: " + tag.name);
let response = await this.#fetchPostsByHashtag(instURL, tag.name);
posts.push(...response);
}
const fetchPromises = hashtags.map(tag => this.#fetchPostsByHashtag(instURL, tag.name));
const timeoutDelay = 10000;
const responses = await Promise.race(
[
Promise.all(fetchPromises),
new Promise((_resolve, reject) => setTimeout(() => reject("Fetch calls timed out."), timeoutDelay)),
]);
const posts = responses.flat();
posts.push(...posts);
return posts;
}
catch (error) {
Expand Down Expand Up @@ -80,7 +83,7 @@ <h1 class="page-title">Source: fetchers/MastodonFetcher.js</h1>
* @returns {Promise&lt;Array>} - A promise that resolves to an array of posts for the given hashtag
*/
async #fetchPostsByHashtag(instURL, hashtag) {
const trendingPostURL = instURL + POST_SUFFIX + hashtag;
const trendingPostURL = instURL + POST_SUFFIX + hashtag + "?limit=" + NUM_MASTODON_POSTS;
try {
const response = await fetch(trendingPostURL);
if (!response.ok) {
Expand Down Expand Up @@ -110,7 +113,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
8 changes: 4 additions & 4 deletions docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="instanceList.js.html">instanceList.js</a>, <a href="instanceList.js.html#line69">line 69</a>
<a href="instanceList.js.html">instanceList.js</a>, <a href="instanceList.js.html#line61">line 61</a>
</li></ul></dd>


Expand Down Expand Up @@ -844,7 +844,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="instanceList.js.html">instanceList.js</a>, <a href="instanceList.js.html#line85">line 85</a>
<a href="instanceList.js.html">instanceList.js</a>, <a href="instanceList.js.html#line77">line 77</a>
</li></ul></dd>


Expand Down Expand Up @@ -1296,7 +1296,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="instanceList.js.html">instanceList.js</a>, <a href="instanceList.js.html#line100">line 100</a>
<a href="instanceList.js.html">instanceList.js</a>, <a href="instanceList.js.html#line92">line 92</a>
</li></ul></dd>


Expand Down Expand Up @@ -1370,7 +1370,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
26 changes: 9 additions & 17 deletions docs/instanceList.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ <h1 class="page-title">Source: instanceList.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>export const DEFAULT_LISTS = {
mastodon: ["https://mastodon.social", "https://fosstodon.org"],
lemmy: ["https://lemmy.ml"],
mastodon: ["https://mastodon.social", "https://fosstodon.org", "https://mstdn.social", "https://mastodon.online", "https://mastodon.world"],
lemmy: ["https://lemmy.ml", "https://lemmy.world", "https://lemm.ee"],
};

const INST_LISTS = "instanceLists";
Expand Down Expand Up @@ -71,17 +71,9 @@ <h1 class="page-title">Source: instanceList.js</h1>
* @returns {Promise&lt;boolean>} Promise which resolves to True if the instance addition was successful, False otherwise
*/
export async function addInstance(network, url, storage = localStorage) {
// TODO: move validation out of this function? (may separate concerns better)
if (!(ALLOWED_NETWORKS.has(network)) || !validUrl(url)) return false;
// Commented out because this creates CORS errors if not done exactly on API
// try {
// let response = await fetch(url);
// if (response.status !== 200) return false;
// } catch (_) {
// return false;
// }

let instanceList = fetchInstanceLists(storage);

const instanceList = fetchInstanceLists(storage);
// network is already guaranteed to be in ALLOWED_NETWORKS and thus on the default list
instanceList[network].unshift(url);
storage.setItem(INST_LISTS, JSON.stringify(instanceList));
Expand All @@ -95,9 +87,9 @@ <h1 class="page-title">Source: instanceList.js</h1>
* @param {Storage} storage
*/
export function handleRemoveInstance(network, url, storage = localStorage) {
let i = removeInstance(network, url, storage);
const i = removeInstance(network, url, storage);
if (i !== -1) {
let list = document.getElementById(`${network}-instance-list`);
const list = document.getElementById(`${network}-instance-list`);
// first child will always be add instance input box
// index 0 of instance list will be child 1
list.removeChild(list.children[i + 1]);
Expand All @@ -111,9 +103,9 @@ <h1 class="page-title">Source: instanceList.js</h1>
* @returns {number} Index removed if successful, -1 otherwise
*/
export function removeInstance(network, url, storage = localStorage) {
let instanceLists = fetchInstanceLists(storage);
const instanceLists = fetchInstanceLists(storage);
if (network in instanceLists &amp;&amp; instanceLists[network].includes(url)) {
let ind = instanceLists[network].indexOf(url);
const ind = instanceLists[network].indexOf(url);
instanceLists[network].splice(ind, 1);
saveLists(instanceLists, storage);
return ind;
Expand Down Expand Up @@ -150,7 +142,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/js_doc_test.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Paginator
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 01:02:11 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 01:16:30 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
25 changes: 14 additions & 11 deletions docs/pageBuilder.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,29 @@ <h1 class="page-title">Source: pageBuilder.js</h1>
nextPage.disabled = true;
prevPage.disabled = true;

// TODO: sane pre-fetching solution that isn't just one instance
let postsByNetwork = {};
const postsByNetwork = {};
let maxLengthArray = 0;
const instLists = fetchInstanceLists();
for (let [network, instanceList] of Object.entries(instLists)) {
let fetcher = new HANDLERS[network]["fetcher"]();
let postBuilder = new HANDLERS[network]["postBuilder"]();
// Iterate over networks (currently just Mastodon and Lemmy)
for (const [network, instanceList] of Object.entries(instLists)) {
// Get object handlers for API and post formatting
const fetcher = new HANDLERS[network]["fetcher"]();
const postBuilder = new HANDLERS[network]["postBuilder"]();
postsByNetwork[network] = [];
for (let url of instanceList) {
let res = await fetcher.fetchPosts(url);
for (let post of res) {
// Iterate over each network's instance list
for (const url of instanceList) {
const res = await fetcher.fetchPosts(url);
if (res === null) continue;
for (const post of res) {
postsByNetwork[network].push(postBuilder.buildPost(post));
}
}
maxLengthArray = Math.max(maxLengthArray, postsByNetwork[network].length);
}

let posts = [];
const posts = [];
for (let i = 0; i &lt; maxLengthArray; i++) {
for (let [network, _] of Object.entries(instLists)) {
for (const [network] of Object.entries(instLists)) {
if (i &lt; postsByNetwork[network].length) {
posts.push(postsByNetwork[network][i]);
}
Expand Down Expand Up @@ -101,7 +104,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="InstanceE
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Dec 12 2023 18:54:17 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Dec 13 2023 06:09:20 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading

0 comments on commit ecd289d

Please sign in to comment.