Commit Graph

219 Commits

Author SHA1 Message Date
Eric Eastwood addb02198d
Don't jump calendar around for events which appear in the future (#196)
Don't jump calendar around for events which appear in the future compared to the timestamp in the URL.

This sort of situation occurs often for Gitter imported historical rooms where we have a bunch of history that is timestamp massaged intermixed with a bunch of join events which we couldn't timestamp massage at the time.

Fix https://github.com/matrix-org/matrix-public-archive/issues/182
2023-04-27 03:16:06 -05:00
Eric Eastwood 53a1d4b43b
Update docs in preparation for Matrix Public Archive being generally available (#194) 2023-04-27 00:22:41 -05:00
Eric Eastwood ab9154bec2
Fix typos where I mispelled homeserver (#195) 2023-04-27 00:00:56 -05:00
Eric Eastwood 13f66c6d9d
Add note that public/ is copied as-is (#193) 2023-04-26 17:08:43 -05:00
Eric Eastwood f71fc2bb9c
Cache derived info from the `manifest.json` (#191)
- Like getting all of the dependencies for a given entry point
 - And the favicons
 
Also fix the problem where `server/hydrogen-render/render-page-html.js` was calling `getFaviconAssetUrls()` right away before the client build had a chance to generate `dist/manifest.json` and result in `Error: Cannot find module '../../dist/manifest.json'`
2023-04-26 17:04:49 -05:00
Eric Eastwood c297270f39
Link prior art and reasoning why we still always join before (#190)
See https://github.com/matrix-org/matrix-public-archive/issues/50
2023-04-26 16:39:53 -05:00
Eric Eastwood e20a67d2ba
Preload fonts and images (#187)
Part of https://github.com/matrix-org/matrix-public-archive/issues/132
2023-04-26 16:35:00 -05:00
Eric Eastwood f0a11139cb
Update Hydrogen SDK dependency `0.26.0-scratch` - 2023-04-26 (#189)
Of note:

 - Adds date headers, https://github.com/vector-im/hydrogen-web/pull/938
 - Add "Copy matrix.to permalink" message action, https://github.com/vector-im/hydrogen-web/pull/921
 - Removes `?v=3.13` query parameters from Inter font references in CSS, https://github.com/vector-im/hydrogen-web/pull/961
    - This is what we need to solve https://github.com/matrix-org/matrix-public-archive/pull/187#discussion_r1177638781
2023-04-26 16:18:34 -05:00
Eric Eastwood bc900f99b5
Make sure we still convert from CommonJS to ESM even when symlinking `hydrogen-view-sdk` locally (#188)
References:

 - https://github.com/rollup/plugins/tree/master/packages/commonjs#usage-with-symlinks
 - https://vitejs.dev/config/shared-options.html#resolve-preservesymlinks
 - https://github.com/vitejs/vite/issues/2405 -> https://github.com/vitejs/vite/pull/4708/files
 - https://rollupjs.org/configuration-options/#preservesymlinks
2023-04-26 15:38:50 -05:00
Eric Eastwood 27863a1945
Iterate on `crossorigin` language in `Link` preload header comments (#186)
Hopefully more accurate now 🤞
2023-04-26 04:05:11 -05:00
Eric Eastwood a3952f1d31
Fix preload link headers (#185)
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/171 and https://github.com/matrix-org/matrix-public-archive/pull/175 where they broke because we went from scripts to modules.

Part of https://github.com/matrix-org/matrix-public-archive/issues/132

Before this PR, we were seeing these warning in the Chrome devtools console:

```
A preload for 'foo' is found, but is not used because the request credentials mode does not match. Consider taking a look at crossorigin attribute.
```

This is caused by a credentials mode mismatch between the `<script type="module">` tag and the `Link` header. A `<script type="module">` with no `crossorigin` attribute indicates a credentials mode of `omit` and a naive `Link: </foo-url>; rel=preload; as=script;` has a  default credentials mode of `same-origin`, hence the mismatch and warning we're seeing.

We could set the credentials mode to match using `Link: </foo-url>; rel=preload; as=script; omit` but there is an even better option! We can use the dedicated `Link: </foo-url>; rel=modulepreload` link type which not only downloads and puts the the file in the cache like a normal preload but the browser also knows it's a JavaScript module now and can parse/compile it so it's ready to go.

---

Future consideration: Adding `nopush` to preload link headers. Many servers initiate an HTTP/2 Server Push when they encounter a preload link in HTTP header form otherwise. Do we want/care about that (or maybe we don't)? (mentioned in https://medium.com/reloading/preload-prefetch-and-priorities-in-chrome-776165961bbf#6f54)

---

References for preload `Link` headers:

  - https://medium.com/reloading/preload-prefetch-and-priorities-in-chrome-776165961bbf#6f54
  - https://html.spec.whatwg.org/multipage/links.html#link-type-preload
  - https://www.smashingmagazine.com/2016/02/preload-what-is-it-good-for/#headers
 - https://developer.chrome.com/blog/modulepreload/#ok-so-why-doesnt-link-relpreload-work-for-modules
2023-04-26 03:29:57 -05:00
Eric Eastwood d3e35a5de1
Make sure to restart the server after Vite `manifest.json` changes (#184)
Make sure to restart the server after Vite `manifest.json` changes so it can pick up the latest and serve pages correctly.
2023-04-26 02:09:46 -05:00
Eric Eastwood 2c12fec1e6
Fix scripts not loading from the production ready build PR (#183)
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/175
2023-04-25 03:54:49 -05:00
Eric Eastwood 630e58fadc
Remove stray logs (#181)
Accidentally introduced in https://github.com/matrix-org/matrix-public-archive/pull/175
2023-04-25 01:21:53 -05:00
Eric Eastwood ac1419cdca
Only `require.resolve(...)` the path once (#180)
Perhaps an early optimization or not even needed but doesn't seem wise to keep pulling this over and over (best case it's cached).
2023-04-25 00:50:43 -05:00
Eric Eastwood 0f26dc94d3
Migrate from `eslint-plugin-node` to `eslint-plugin-n` (#179) 2023-04-25 00:39:59 -05:00
Eric Eastwood 6c38f47a0c
Move escape-string-regexp to a normal dep since we use it on the server (#178) 2023-04-25 00:10:01 -05:00
Eric Eastwood 9c0b6fe85e
Production ready build (#175)
- Rename `public` -> `client` so it doesn't get copied automagically as-is (without hashes which we want for cache busting), https://vitejs.dev/guide/assets.html#the-public-directory
     - We still build the version files to `public/` so their copied as-is and Vite handles it for us (so we can use `emptyOutDir`) 
 - Use a multiple entrypoint `.js` Vite build so things can be more intelligently bundled and take less time
     - We aren't using library mode because it doesn't minify or bundle assets
 - Using hash asset tags for cache busting. Hash of the file included in the file name
 - We lookup these hashed assets from `manifest.json` that Vite builds (https://vitejs.dev/guide/backend-integration.html) to serve and preload
 - In terms of optimized bundles, I know the current output isn't great now but will have to opt to fix that up separately in the future. Tracked by https://github.com/matrix-org/matrix-public-archive/issues/176
2023-04-24 23:50:53 -05:00
Eric Eastwood 50a1d658e8
Only read version tag files once on startup (#174)
We already read it once for the `/health-check` endpoint and cached the response but this way we can use `getVersionTags()` everywhere without worrying about it.

Also, it's no longer `async` so we can use it in things like Express route paths and CDN asset tags more easily.
2023-04-19 15:57:22 -05:00
Eric Eastwood 78ee88e094
Add route identifiers for easy metric reporting (#173)
Pre-requisite for https://github.com/matrix-org/matrix-public-archive/issues/162 and https://github.com/matrix-org/matrix-public-archive/issues/148
2023-04-19 15:09:51 -05:00
Eric Eastwood 27afaea8ca
Serve Hydrogen assets from `/hydrogen-assets/` sub-directory for easier targeting of cache rules (#172)
Fix https://github.com/matrix-org/matrix-public-archive/issues/160
2023-04-19 14:44:12 -05:00
Eric Eastwood 17a39ab8db
Add preload link headers for downstream Cloudflare early hints (#171)
Because it takes us at best several seconds to request information from a homeserver and then server-side render the page, the browser has to wait for the response before it can even try loading the necessary assets. With this change that facilitates early hints, the browser can preload all of the assets necessary before we are done generating the response and will be ready to go by the time we're all done on the server.

Fix https://github.com/matrix-org/matrix-public-archive/issues/32

Part of https://github.com/matrix-org/matrix-public-archive/issues/132

See https://developers.cloudflare.com/cache/about/early-hints/ for information on enabling in Cloudflare
2023-04-19 14:20:01 -05:00
Eric Eastwood 321c6a4f26
Slightly easier to understand renderHydrogenVmRenderScriptToPageHtml API surface (#170) 2023-04-19 13:48:12 -05:00
Eric Eastwood 551b4e72d1
Follow tombstone and predecessor history (#167)
Fix https://github.com/matrix-org/matrix-public-archive/issues/59

Other updates:

 - Update tests to use `/roomid/room1/date/2022/01/03` format instead of trying to retrofit the weird alias stuff on there. Which also makes the fancy to actual URL utilities much more simple.
 - Update to specify `archiveMessageLimit` in the test case because pages have different number of events depending on if we are against a boundary, hidden events, etc.
2023-04-19 01:26:15 -05:00
Eric Eastwood 6c789eae69
Do our best to get the user to the right place and try joining `via` derived server name (#168)
Split out from https://github.com/matrix-org/matrix-public-archive/pull/167
2023-04-11 15:09:44 -05:00
Eric Eastwood e99a0d6912
Rename to build-scripts to it appears in GitHub file finder (#166)
It seems like the `build/` directory is ignored in the GitHub file
finder as a sane default for people who put compiled assets there.

`build-scripts/` probably makes more sense anyway
2023-04-07 13:17:46 -05:00
Eric Eastwood 5aafa01f38
Update linting so we don't need omit the context filling name of some variables (#165)
`"no-unused-vars": ["error", { "destructuredArrayIgnorePattern": "^_" }],` was only [introduced in `eslint@8.11.0`](0fd6bb213a/CHANGELOG.md) so we had to update
2023-04-07 13:01:20 -05:00
Eric Eastwood 57d2cb3dd3
Refactor tests to use single source of truth ASCII diagram (#164)
- Less test bulk
 - Single source of truth: there is no mismatch between the comment and the expectations (we already caught a few mistakes in the conversion thanks to this benefit)
 - Easier to maintain and update
2023-04-07 12:52:41 -05:00
Eric Eastwood 954b22995a
Add a way to select time of day (#139)
- Fix https://github.com/matrix-org/matrix-public-archive/issues/7
 - A URL with time looks like
    - `/r/too-many-messages-on-day:my.synapse.server/date/2022/11/16T23:59`
    - Or when more precision is required (seconds): `/r/too-many-messages-on-day:my.synapse.server/date/2022/11/16T23:59:59`
 - Add new custom time picker/scrubber (pictured below) with momentum scrubbing
    - Native built-in `<input type="time">` for easier picking if you prefer that and accessibility.
    - Uses localized time strings
    - Design inspired by Thiago Sanchez's *Time Zone Translate* concept, https://dribbble.com/shots/14590546-Time-Zone-Translate
2023-04-05 04:25:31 -05:00
Eric Eastwood b0cee80253
Update docs to reflect that we need stable MSC3030 /timstamp_to_event (#159)
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/154
2023-02-17 02:35:23 -06:00
Philip Durbin 8f9e1631ae
Switch /timestamp_to_event from unstable to stable v1 #142 (#154) 2023-02-16 20:52:28 -06:00
Eric Eastwood 7125657636
Update readme to reflect more fleshed out actuality (#156) 2023-01-16 13:40:08 -06:00
Philip Durbin f95086df0d
Link to demo videos (#153)
Fix #150
2022-12-12 12:03:34 -06:00
Jemimah Nagasha 7893e5bd5d
Link our Matrix room from the readme (#151)
Fix: #140
2022-12-06 21:23:31 -06:00
Michael[tm] Smith 2999691eea
Enable CORS support (#147)
This change enables CORS support in the archive — to allow web developers to create web applications with frontend JavaScript code that can fetch pages from the archive (for example, for scraping content from chat logs).

Otherwise, without this change, web developers can’t create web apps with frontend JavaScript that can fetch chat logs from the archive and then consume the content of the logs.

It’s imaginable that web developers may find use cases for consuming the chat logs in the archive from frontend JavaScript code — at the simplest level, web apps that fetch and scrape logs to get data out of them or to pull out particular snippets from the logs.

Developers can anyway already scrape the contents of the archive — by using server-side programming languages or by using `curl` or whatever from the command line. They just can’t do the same from frontend JavaScript code, unless CORS support is enabled.
2022-11-28 21:47:57 -06:00
Michael[tm] Smith 6b493ff807
Only assign `vmContext.global.crypto` if not already global (#143)
Fixes https://github.com/matrix-org/matrix-public-archive/issues/141

Node.js v19 has `crypto` set on the global already, so this change causes `vmContext.global.crypto` to be assigned only if `vmContext.global.crypto` isn’t already defined.

Otherwise, without this change, the room directory fails to render in Node.js v19+, and instead _"TypeError: Cannot set property crypto of `#<Object>` which has only a getter"_ gets thrown.
2022-11-18 12:27:50 -06:00
Eric Eastwood 6e2a56d726
Update readme with creature comforts and MSC3030-enabled server prerequisite (#144)
Spawning from https://github.com/matrix-org/matrix-public-archive/issues/142
2022-11-18 03:29:57 -06:00
Eric Eastwood b41d15a92c
Add `Copy permalink` option to messages (`matrix.to`) (#136)
This might be a little ambiguous since we'll have permalinks within the Matrix Public Archive with `?at=$xxx` (related https://github.com/matrix-org/matrix-public-archive/issues/137) which is different from `matrix.to` permalinks 🤔

But will just go with it for now 
2022-11-14 17:55:00 -06:00
Eric Eastwood 11cbf39460
Add Matrix favicon (#135)
It's a cleaned up version of what [Matrix.org](https://matrix.org/) is using since that one is [so blurry](https://user-images.githubusercontent.com/558581/201302097-411b8033-4281-4cd3-a069-0c97ba3aa01f.png).

Part of https://github.com/matrix-org/matrix-public-archive/issues/94
2022-11-11 14:50:41 -06:00
Eric Eastwood 776347207e
Updates to be compatible with the latest Hydrogen changes (rename `urlCreator` -> `urlRouter`) (#134)
Hydrogen changes:

 - https://github.com/vector-im/hydrogen-web/pull/918
2022-11-10 17:37:08 -06:00
Eric Eastwood 8a2dabe97b
Fix room image avatars not showing in the room directory (#133)
Fix room image avatars not showing in the room directory

Fix https://github.com/matrix-org/matrix-public-archive/issues/95
2022-11-10 00:29:44 -06:00
Eric Eastwood 3d604a1d87
Update Hydrogen SDK dependency 0.23.0-scratch (#131) 2022-11-09 19:07:30 -06:00
Eric Eastwood fa4720af04
Increase perceived performance by scrolling to the right spot before Hydrogen loads (#128) 2022-11-09 18:57:33 -06:00
Eric Eastwood 3671da0405
Fix NPE with non-existent event permalink `?at=$doesnotexist` (#130) 2022-11-09 02:07:10 -06:00
Eric Eastwood dc85e839a1
Add config to disable search engine indexing (#127) 2022-11-08 22:41:58 -06:00
Eric Eastwood b3c553a863
Add comment reference to issue about adding hour chunk time slices (#126) 2022-11-08 22:35:28 -06:00
Eric Eastwood 026a08a77a
Jump forward and backward seamlessly (#121)
Fix https://github.com/matrix-org/matrix-public-archive/issues/120
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/114

 - Uses event permalinking (`?at=$xxx`) to continue the scroll where you should start reading again.
 - When we jump forwards, we make sure that we go a day back to ensure there isn't more than the page limit between where we jumped from and the day so we don't lose any messages in a gap.
2022-11-03 05:06:53 -05:00
Eric Eastwood 5bae040d72
Add permalink highlighting - `?at=$xxx` (#123)
ex.
```
http://localhost:3050/r/test-room1:my.synapse.server/date/2022/07/28?at=$O9fDg42JoSh9VdcL820FDUS0Gi_CkPt_hrN1pK1fPEY
````

Fix https://github.com/matrix-org/matrix-public-archive/issues/4

Split out from https://github.com/matrix-org/matrix-public-archive/pull/121
2022-11-03 04:49:07 -05:00
Eric Eastwood 2dff7ecea5
Refactor `fetchEndpointAsText`/`fetchEndpointAsJson` to return `res` alongside `data` (#122)
Split out of https://github.com/matrix-org/matrix-public-archive/pull/121
where we needed to use `res.url`.
2022-11-03 04:12:00 -05:00
Eric Eastwood 91d84fcc08
Don't change the URL as you scroll around (#119)
Fix https://github.com/matrix-org/matrix-public-archive/issues/115

Reverting behavior originally introduced in https://github.com/matrix-org/matrix-public-archive/pull/71
2022-11-02 04:35:36 -05:00