Pass config so images render with correct media repo

This commit is contained in:
Eric Eastwood 2022-02-09 01:49:02 -06:00
parent a49657f9e3
commit 1c7c6bf440
3 changed files with 19 additions and 12 deletions

View File

@ -4,7 +4,7 @@ const fetch = require('node-fetch');
const { matrixServerUrl } = require('../config.json'); const { matrixServerUrl } = require('../config.json');
const secrets = require('../secrets.json'); const secrets = require('../secrets.json');
const matrixAccessToken = secrets['matrix-access-token']; const matrixAccessToken = secrets.matrixAccessToken;
assert(matrixAccessToken); assert(matrixAccessToken);
class HTTPResponseError extends Error { class HTTPResponseError extends Error {
@ -44,8 +44,6 @@ async function fetchEventsForTimestamp(roomId, ts) {
matrixServerUrl, matrixServerUrl,
`_matrix/client/unstable/org.matrix.msc3030/rooms/${roomId}/timestamp_to_event?ts=${ts}&dir=f` `_matrix/client/unstable/org.matrix.msc3030/rooms/${roomId}/timestamp_to_event?ts=${ts}&dir=f`
); );
console.log('timestampToEventEndpoint', timestampToEventEndpoint);
const timestampToEventResData = await fetchEndpoint(timestampToEventEndpoint); const timestampToEventResData = await fetchEndpoint(timestampToEventEndpoint);
//console.log('timestampToEventResData', timestampToEventResData); //console.log('timestampToEventResData', timestampToEventResData);
@ -61,11 +59,12 @@ async function fetchEventsForTimestamp(roomId, ts) {
const messagesEndpoint = path.join( const messagesEndpoint = path.join(
matrixServerUrl, matrixServerUrl,
`_matrix/client/r0/rooms/${roomId}/messages?from=${contextResData.start}&limit=100&filter={"lazy_load_members":true,"include_redundant_members":true}` `_matrix/client/r0/rooms/${roomId}/messages?from=${contextResData.start}&limit=50&filter={"lazy_load_members":true,"include_redundant_members":true}`
); );
const messageResData = await fetchEndpoint(messagesEndpoint); const messageResData = await fetchEndpoint(messagesEndpoint);
//console.log('messageResData', messageResData); //console.log('messageResData', messageResData);
//console.log('messageResData.state', messageResData.state);
const stateEventMap = {}; const stateEventMap = {};
for (const stateEvent of messageResData.state) { for (const stateEvent of messageResData.state) {
if (stateEvent.type === 'm.room.member') { if (stateEvent.type === 'm.room.member') {

View File

@ -13,6 +13,14 @@ const {
TimelineView, TimelineView,
} = require('hydrogen-view-sdk'); } = require('hydrogen-view-sdk');
const events = global.INPUT_EVENTS;
assert(events);
const stateEventMap = global.INPUT_STATE_EVENT_MAP;
assert(stateEventMap);
const config = global.INPUT_CONFIG;
assert(config);
assert(config.matrixServerUrl);
let eventIndexCounter = 0; let eventIndexCounter = 0;
const fragmentIdComparer = new FragmentIdComparer([]); const fragmentIdComparer = new FragmentIdComparer([]);
function makeEventEntryFromEventJson(eventJson, memberEvent) { function makeEventEntryFromEventJson(eventJson, memberEvent) {
@ -40,17 +48,13 @@ function makeEventEntryFromEventJson(eventJson, memberEvent) {
} }
async function mountHydrogen() { async function mountHydrogen() {
const events = global.INPUT_EVENTS;
assert(events);
const stateEventMap = global.INPUT_STATE_EVENT_MAP;
assert(stateEventMap);
const app = document.querySelector('#app'); const app = document.querySelector('#app');
const config = {}; const platformConfig = {};
const assetPaths = {}; const assetPaths = {};
const platform = new Platform(app, assetPaths, config, { development: true }); const platform = new Platform(app, assetPaths, platformConfig, { development: true });
// We use the timeline to setup the relations between entries
const timeline = new Timeline({ const timeline = new Timeline({
roomId: roomId, roomId: roomId,
//storage: this._storage, //storage: this._storage,
@ -65,7 +69,7 @@ async function mountHydrogen() {
roomVM: { roomVM: {
room: { room: {
mediaRepository: new MediaRepository({ mediaRepository: new MediaRepository({
homeserver: 'https://matrix-client.matrix.org', homeserver: config.matrixServerUrl,
}), }),
}, },
}, },
@ -97,6 +101,7 @@ async function mountHydrogen() {
timeline._setupEntries([]); timeline._setupEntries([]);
// Make it safe to iterate a derived observable collection // Make it safe to iterate a derived observable collection
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null }); timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
// We use the timeline to setup the relations between entries
timeline.addEntries(eventEntries); timeline.addEntries(eventEntries);
//console.log('timeline.entries', timeline.entries.length, timeline.entries); //console.log('timeline.entries', timeline.entries.length, timeline.entries);

View File

@ -5,6 +5,8 @@ const { readFile } = require('fs').promises;
const crypto = require('crypto'); const crypto = require('crypto');
const { parseHTML } = require('linkedom'); const { parseHTML } = require('linkedom');
const config = require('../config.json');
async function renderToString(events, stateEventMap) { async function renderToString(events, stateEventMap) {
assert(events); assert(events);
assert(stateEventMap); assert(stateEventMap);
@ -40,6 +42,7 @@ async function renderToString(events, stateEventMap) {
vmContext.global.INPUT_EVENTS = events; vmContext.global.INPUT_EVENTS = events;
vmContext.global.INPUT_STATE_EVENT_MAP = stateEventMap; vmContext.global.INPUT_STATE_EVENT_MAP = stateEventMap;
vmContext.global.INPUT_CONFIG = config;
const hydrogenRenderScriptCode = await readFile( const hydrogenRenderScriptCode = await readFile(
path.resolve(__dirname, './hydrogen-vm-render-script.js'), path.resolve(__dirname, './hydrogen-vm-render-script.js'),