diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 296b14a7..00000000 --- a/.dockerignore +++ /dev/null @@ -1,12 +0,0 @@ -.djlintrc -.env -.env.* -.eslintrc.cjs -.github -.husky -.prettierrc -CHANGELOG.md -CONTRIBUTING.md -LICENSE.md -README.md -node_modules \ No newline at end of file diff --git a/.env.example b/.env.example deleted file mode 100644 index 17010991..00000000 --- a/.env.example +++ /dev/null @@ -1,4 +0,0 @@ -USERNAME= -PASS= -DOMAIN= -PORT= diff --git a/.eslintrc.cjs b/.eslintrc.cjs index d0303475..b48fbc95 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -12,5 +12,6 @@ module.exports = { sourceType: 'module' }, rules: { - } + }, + ignorePatterns: ["**/*.jest.js", "**/prettify"], } diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 00000000..0ac616c7 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,31 @@ +name: Running Code Coverage + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x, 16.x] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 2 + + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm run test + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8f5e43a1..8346c8fd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -26,7 +26,7 @@ jobs: - name: Configure Node.js uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - name: Retrieve npm cache uses: 'actions/cache@v3' @@ -37,7 +37,7 @@ jobs: ${{ runner.os }}-node- - name: Install Node packages - run: npm ci + run: npm install && npm ci - name: Get changed files id: changes run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..131ba90d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Unit Tests + +on: [push, pull_request] + +jobs: + tests: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x, 16.x] + + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test diff --git a/.gitignore b/.gitignore index 8c959a91..8831aaf4 100644 --- a/.gitignore +++ b/.gitignore @@ -321,5 +321,4 @@ $RECYCLE.BIN/ # and uncomment the following lines # .pnp.* -# End of https://www.toptal.com/developers/gitignore/api/macos,linux,windows,webstorm,yarn,diff,snyk,node,tower - +# End of https://www.toptal.com/developers/gitignore/api/macos,linux,windows,webstorm,yarn,diff,snyk,node,tower \ No newline at end of file diff --git a/.jest/setEnvVars.js b/.jest/setEnvVars.js new file mode 100644 index 00000000..9b1e0f5c --- /dev/null +++ b/.jest/setEnvVars.js @@ -0,0 +1 @@ +process.env.DOMAIN = 'testDomain'; diff --git a/CHANGELOG.md b/CHANGELOG.md index ea75f39c..30e9316b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,60 +1,70 @@ -# How to update - -For now, the best way to upgrade is to pull the latest code from the main branch. -(One day I'll set up proper packaging with versions and stuff. That day is not today!) - -* Type `git pull origin main` -* Make sure to restart the app afterwards - -# CHANGE LOG - -## 2023-01-30 -- Fixed the missing edit button -- Fixed a bug where people without a `name` field would show up blank in some places -- Fixed a bug related to missing environment variables - -## 2023-01-29 -- Introduced a background queue system for handling outbound HTTP requests. -- Fixed follows - outbound follow requests got disabled on 01/23! Oops! -- Fixed communication with Pixelfed and GoToSocial instances. Follows and stuff should now work! - -## 2023-01-23 -- Added linting and code prettification as a pre-commit hook -- Added Github actions to run linter rules and enforce them on PRs -Huge thanks to @selfagency for these improvements! - -## 2023-01-15 -- Added a prefs page -- Added the ability to change all the emojis in the UI 👹 -- Added the ability to change what it says on the "post" button -See a video of these features in action here: https://www.loom.com/share/c8fbe3b099f644d596cd2db26e86bc8a - - -## 2023-01-14 -- All new nav! There is now a list of the 20 most recently updated feeds in the nav. Click "..." to see up to 100. -- Lots of CSS improvements! -- When you search for a user, Shuttlecraft will now also search all known users - - -## 2023-01-12 -- Prevent buttons from being double-clicked resulting in accidentally undoing something or double posting -- Prevent the account.json file from being created with a faulty domain name. Thanks @patrickmcurry! - - -## 2023-01-09 -- Fixed a bug causing new posts not to show up til the server restarts. Oops! - -## 2023-01-08 -- Added support for incoming DELETE activities. This causes matching posts to be completely removed from the system. As part of this, increased resilience for dealing with missing or unreachable posts. Thanks to @ringtailsoftware. -- Added support for editing local posts. Thanks to @ringtailsoftware. -- Renamed the sample .env to .env.example and introduced a post-install script to copy it into place -- Created this changelog! - -## 2023-01-07 -- Links in posts now automatically include noopen noreferer nofollow attributes. - -## 2023-01-06 -- Support for light/dark themes. Thanks @anildash -- Fix pagination bugs, add pagination on notifications - - +# How to update + +For now, the best way to upgrade is to pull the latest code from the main branch. +(One day I'll set up proper packaging with versions and stuff. That day is not today!) + +- Type `git pull origin main` +- Make sure to restart the app afterwards + +# CHANGE LOG + +## 2023-01-30 + +- Fixed the missing edit button +- Fixed a bug where people without a `name` field would show up blank in some places +- Fixed a bug related to missing environment variables + +## 2023-01-29 + +- Introduced a background queue system for handling outbound HTTP requests. +- Fixed follows - outbound follow requests got disabled on 01/23! Oops! +- Fixed communication with Pixelfed and GoToSocial instances. Follows and stuff should now work! + +## 2023-01-23 + +- Added linting and code prettification as a pre-commit hook +- Added Github actions to run linter rules and enforce them on PRs + Huge thanks to @selfagency for these improvements! + +## 2023-01-15 + +- Added a prefs page +- Added the ability to change all the emojis in the UI 👹 +- Added the ability to change what it says on the "post" button + See a video of these features in action here: https://www.loom.com/share/c8fbe3b099f644d596cd2db26e86bc8a + +## 2023-01-14 + +- All new nav! There is now a list of the 20 most recently updated feeds in the nav. Click "..." to see up to 100. +- Lots of CSS improvements! +- When you search for a user, Shuttlecraft will now also search all known users + +## 2023-01-12 + +- Prevent buttons from being double-clicked resulting in accidentally undoing something or double posting +- Prevent the account.json file from being created with a faulty domain name. Thanks @patrickmcurry! + +## 2023-01-09 + +- Fixed a bug causing new posts not to show up til the server restarts. Oops! + +## 2023-01-08 + +- Added support for incoming DELETE activities. This causes matching posts to be completely removed from the system. As part of this, increased resilience for dealing with missing or unreachable posts. Thanks to @ringtailsoftware. +- Added support for editing local posts. Thanks to @ringtailsoftware. +- Renamed the sample .env to .env.example and introduced a post-install script to copy it into place +- Created this changelog! + +## 2023-01-07 + +- Links in posts now automatically include noopen noreferer nofollow attributes. + +## 2023-01-06 + +- Support for light/dark themes. Thanks @anildash +- Fix pagination bugs, add pagination on notifications + +## 2023-12-08 - USERNAME Crossplatform Compatibility + +- Fixed bug of USERNAME variable not working on windows machines. +- Instead of using USERNAME we now use USER_NAME diff --git a/Caddyfile b/Caddyfile deleted file mode 100644 index 23c5f04f..00000000 --- a/Caddyfile +++ /dev/null @@ -1,3 +0,0 @@ -localhost { - reverse_proxy :3000 -} diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index fe3c22e8..00000000 --- a/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -FROM node:16-alpine - -# Create volume for persistent data -VOLUME /app/.data - -# Create app directory -WORKDIR /app - -# Install deps -COPY package.json ./ -COPY package-lock.json ./ -RUN npm ci --omit=dev --ignore-scripts - -# Copy source -COPY . . - -# Env Vars -ENV PORT=3000 -ENV DOMAIN="" -ENV USERNAME="" -ENV PASS="" - -# Expose port -EXPOSE $PORT - -# Start program -CMD [ "npm", "start" ] diff --git a/README.md b/README.md index e5fd7e50..0a03bb60 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,19 @@ -# SHUTTLECRAFT by Ben Brown +# SHUTTLECRAFT by the Confused Mavericks This is a project to create an "easy" way to participate in the ActivityPub "Fediverse" and other indie web protocols like RSS. -This was created and is maintained by [Ben Brown](https://benbrown.com). +This was created by [Ben Brown](https://benbrown.com) and enhanced by UCSD CSE 210 Team 6 (Confused Mavericks). Currently, this means: -- a stand-alone NodeJS web application +- a stand-alone NodeJS web application - with no external service dependencies - that is hostable on Glitch or commodity virtualhost Including features: + +- Create a fediverse account - Follow people (on Mastodon, other instances) +- Customize your fediverse profile - Compose posts and deliver on the web, and also via ActivityPub, RSS - Fave, boost and reply to posts - View notifications @@ -18,9 +21,10 @@ Including features: - Block people or instances Not yet supported: + - Media uploads -## Warning: Experimental Software! +## Warning: Experimental Software! This software should be considered an EXPERIMENTAL PROTOTYPE. Do not use it to store or exchange sensitive information. @@ -32,29 +36,22 @@ Do not use it to store or exchange sensitive information. Because of the way the Mastodon works, once you start to engage with users on other instances, you will start to receive traffic from a -wide array of other instances -- not all of which is necessary or +wide array of other instances -- not all of which is necessary or relevant to you. As a result, operating this software on a small basis may result in unexpected amounts of incoming traffic. ## Warning: Known limitations! -My goal with this app is to not use any major external services. +Our goal with this app is to not use any major external services. As a result, all data is written as PLAIN TEXT FILES to the disk. Right now, the app builds an IN-MEMORY INDEX of EVERY SINGLE POST. This will work for several thousand posts, but ... maybe not for 10,000s of posts. -I'm not sure how far it will go. I have ideas about being able to -shard the index into multiple files and page through it, etc. But. ALSO, there is nothing fancy happening in terms of queuing or rate limiting outgoing posts. When you post, it will send out HTTP requests right away, all at once. This may cause issues. -## Acknowledgements - -This project owes a great debt to @dariusk's excellent [express-activitypub](https://github.com/dariusk/express-activitypub) repo. -My work started from his reference implementation, and there are many lines of code cribbed from his work. - ## Bug Reports & Contributions Please file bugs on Github: @@ -64,26 +61,19 @@ Please read the [contributor's guide](CONTRIBUTING.md) before sending pull reque ## Install -Quick start: [Remix on Glitch](#easiest-glitch) - -Clone the repo: -`git clone git@github.com:benbrown/shuttlecraft.git` +Quick start: [Remix on Glitch](https://glitch.com/edit/#!/import/github/CSE-210-Team-6/shuttlecraft) -Enter folder: -`cd shuttlecraft` +- Remix the repo on glitch: +`https://github.com/CSE-210-Team-6/shuttlecraft.git` -Install node dependencies: -`npm install` +- Go to settings -> Edit project details -> Change the project name to what you want. This will be your website domain You are ready to run! But first, set your configuration. -When you are ready to start, run: -`npm start` - ## Config Initial configuration of your instance is done by editing the -.env file to include your desired USERNAME, PASSWORD, and DOMAIN NAME. +.env file to include your desired DOMAIN NAME. These values MUST BE SET before you launch the application, as they are used to generate your account details, including your Fediverse actor ID. @@ -91,37 +81,27 @@ Fediverse actor ID. In the .env file, put: ``` -USERNAME=yourusername -PASS=yourpasswordforadmintools -DOMAIN=yourdomainname -PORT=3000 +DOMAIN={your-project-name}.glitch.me +PORT={not required but can specify} ``` -USERNAME and PASS are required to login to the private dashboard tools. - When you launch the app for the first time, these values will be used to create the `.data/account.json` file which is the source of your public account information, and will be used for many operations. -There is currently no UI built to view or manage your account. If you -need to make updates, edit the JSON directly. - HOWEVER PLEASE NOTE that your ID is a real URL, and it must reflect the real URL served by this app. Also note that it is embedded in every post you write - so if you change values in the `account.json` file, your previous posts may break. +## Access -## Login - -To login, visit `https://yourdomain.com/private` and provide the username and password from your .env file - - +Access your website at `https://{yourdomain}.com/private`. You will be prompted to create account or login if required. ## Debugging If you want more logging or want to see what is happening in the background, -enable debugging by adding DEBUG=ono:* to the .env file, or starting the app +enable debugging by adding DEBUG=ono:\* to the .env file, or starting the app with: `DEBUG=ono:* npm start` @@ -139,10 +119,9 @@ Cached user information is in `.data/users` Follower list, following list, like list, boost list, block list, and notifications can all be found in their own files at the root -of the `.data` folder. This is your data! Back it up if you care +of the `.data` folder. This is your data! Back it up if you care about it. - ## Host This is a node app that runs by default on port 3000, or the port @@ -151,31 +130,20 @@ specified in the .env file. In order to play nice with the fediverse, it must be hosted on an SSL-enabled endpoint. -### Easiest: Glitch +### Easy: Glitch Use Glitch to create a new project! Glitch will provide you with hosting for your instance of Shuttlecraft, and you can start for FREE! -It all starts when you click this link -> [Remix this project on Glitch](https://glitch.com/edit/#!/import/github/benbrown/shuttlecraft) <-- +It all starts when you click this link -> [Remix this project on Glitch](https://glitch.com/edit/#!/import/github/CSE-210-Team-6/shuttlecraft) <-- WHOA! What happened? Well, a copy of the Shuttlecraft code was sent to a new, unique, owned-by-you web server and it started getting set up. You just need to make it yours by following these steps: 1. First, make sure the URL of your Glitch project is the one you like. You can change it in the "Settings" menu. -2. Then, configure the options [as described above](#config) using the .env editor. -3. Finally, login to the dashboard at `https://yourdomain.glitch.me/private`. -4. Done! - -### Basic: Reverse proxy - -1. Clone the repo to your own server. -2. Configure it and set it up to run on a port of your choosing. -3. Configure Caddy or Nginx with a Certbot SSL certificate. -4. Configure your domain to proxy requests to the localhost port. - -A sample `Caddyfile` is included in the repo. [Install Caddy](https://caddyserver.com/download) and run: -``` -caddy run --config Caddyfile -``` +2. Then, configure the options [as described above](#config) using the .env editor. +3. Finally, create and login to the dashboard at `https://yourdomain.glitch.me/private`. +4. It is very important that the domain you add while creating you user is `https://{yourdomain}.glitch.me`. If not this will break things! +5. Done! ### Advanced: Docker @@ -186,33 +154,37 @@ caddy run --config Caddyfile ``` 3. Test locally: ``` - docker run -e PORT=3000 -e DOMAIN="your-domain.com" -e USERNAME="yourUsername" -e PASS="yourPassword" -p "3000:3000" "${yourRegistryUsername}/shuttlecraft" + docker run -e PORT=3000 -e DOMAIN="your-domain.com" -p "3000:3000" "${yourRegistryUsername}/shuttlecraft" ``` 4. Push the image to your registry: ``` docker push "${yourRegistryUsername}/shuttlecraft:latest" ``` -5. Deploy the image to your container platform with the required environment variables (`DOMAIN`, `USERNAME`, `PASS`). -6. Configure a web service to proxy requests to the container port and provide HTTPS (see "Reverse proxy" above). +5. Deploy the image to your container platform with the required environment variables (`DOMAIN`). +6. Configure a web service to proxy requests to the container port and provide HTTPS (see "Reverse proxy" above). ## Customize This app uses HandlebarsJS for templating. Customize the public pages: + - Templates are in `design/public/home.handlebars` and `design/public/note.handlebars` and `design/layouts/public.handlebars` - CSS is in `public/css/main.css` Customize your avatar: + - Replace `public/images/avatar.png` - As necessary, update the url in `.data/account.json` inside the actor.icon.url field Customize the backend: + - Templates are in `design/dashboard.handlebars` and `design/notifications.handlebars` and `design/layouts/private.handlebars` - Some common components in `design/partials` - CSS in `public/css/secret.css` To block users or instances: + - Add an entry to the file at `.data/blocks` - You can block a user using their actor ID (something like https://foo.bar/@jerk) or their entire domain (https://foo.bar/) -- Restart the app +- Restart the app diff --git a/babel.config.cjs b/babel.config.cjs new file mode 100644 index 00000000..a1db3ce9 --- /dev/null +++ b/babel.config.cjs @@ -0,0 +1,3 @@ +module.exports = { + presets: [['@babel/preset-env', {targets: {node: 'current'}}]], +}; \ No newline at end of file diff --git a/design/createAccount.handlebars b/design/createAccount.handlebars new file mode 100644 index 00000000..585cae8a --- /dev/null +++ b/design/createAccount.handlebars @@ -0,0 +1,32 @@ +
\ No newline at end of file diff --git a/design/dashboard.handlebars b/design/dashboard.handlebars index a9f394c7..49386570 100644 --- a/design/dashboard.handlebars +++ b/design/dashboard.handlebars @@ -20,24 +20,31 @@ {{else}}Follow some people to fill your feed with posts.
-I suggest following me! - I'm benbrown@hackers.town +
We suggest following our Professor Thomas Powell! You can find him at + thomasapowell@fosstodon.org