Skip to content

Commit

Permalink
Persist Build ID in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
brendannee committed Jan 25, 2024
1 parent af386b1 commit 449ff5b
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
GTFS_AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY
GTFS_AWS_ACCESS_KEY_SECRET=YOUR_AWS_SECRET
GTFS_AWS_REGION=us-east-1
GTFS_AWS_S3_URL=https://gtfs-to-html.s3.amazonaws.com
NEXT_PUBLIC_GTFS_AWS_S3_URL=https://gtfs-to-html.s3.amazonaws.com
TRANSIT_FEEDS_API_KEY=YOUR_TRANSIT_FEEDS_API_KEY
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Persist Build ID in URL

## [1.0.4] - 2024-01-24

### Updated
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ If instead there is an error while processing, the response will contain the err

## Upgrading node.js

npm run build
npm install pm2 -g
pm2 update
pm2 unstartup
Expand Down
11 changes: 0 additions & 11 deletions now.json

This file was deleted.

63 changes: 63 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
"hapi-require-https": "^6.0.0",
"lodash-es": "^4.17.21",
"next": "^12.2.5",
"next-query-params": "^5.0.0",
"node-fetch": "^3.3.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-ga": "^3.3.1",
"socket.io": "^4.7.4",
"socket.io-client": "^4.7.4",
"tmp-promise": "^3.0.3",
"use-query-params": "^2.2.1",
"uuid": "^9.0.1"
},
"devDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NextAdapter } from 'next-query-params';
import { QueryParamProvider } from 'use-query-params';

function MyApp({ Component, pageProps: { session, ...pageProps } }) {
return (
<QueryParamProvider adapter={NextAdapter}>
<Component {...pageProps} />
</QueryParamProvider>
);
}

export default MyApp;
21 changes: 20 additions & 1 deletion pages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react';
import Head from 'next/head.js';
import { useQueryParam } from 'use-query-params';

import io from 'socket.io-client';
import { initGA, logPageView, logEvent } from '../util/analytics.js';
Expand Down Expand Up @@ -69,11 +70,11 @@ function Home() {
const [showOptions, setShowOptions] = useState(false);
const [processing, setProcessing] = useState(false);
const [statuses, setStatuses] = useState([]);
const [buildId, setBuildId] = useState();
const [locations, setLocations] = useState();
const [selectedLocation, setSelectedLocation] = useState('');
const [feeds, setFeeds] = useState();
const [selectedFeed, setSelectedFeed] = useState('');
const [buildId, setBuildId] = useQueryParam('build');

const statusContainer = React.createRef();

Expand All @@ -86,6 +87,24 @@ function Home() {
logPageView();
}, []);

useEffect(() => {
if (buildId && statuses.length === 0) {
setStatuses([
{
status: 'Timetable creation completed',
html_download_url: new URL(
`/${buildId}/timetables.zip`,
process.env.NEXT_PUBLIC_GTFS_AWS_S3_URL,
),
html_preview_url: new URL(
`/${buildId}/index.html`,
process.env.NEXT_PUBLIC_GTFS_AWS_S3_URL,
),
},
]);
}
}, [buildId]);

useEffect(() => {
socket.on('status', (payload) => {
if (statuses.length > 0 && payload.overwrite === true) {
Expand Down
8 changes: 4 additions & 4 deletions util/create.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {join} from 'node:path';
import {fileURLToPath, resolve} from 'node:url';
import {fileURLToPath} from 'node:url';
import {readFile, stat, writeFile} from 'node:fs/promises';
import fetch from 'node-fetch';
import { throttle } from 'lodash-es';
Expand Down Expand Up @@ -123,9 +123,9 @@ export default async (data, socket) => {
uploader.on('end', () => {
setTimeout(() => {
socket.emit('status', {
status: 'Timetable upload completed',
html_download_url: resolve(process.env.GTFS_AWS_S3_URL, join(buildId, 'timetables.zip')),
html_preview_url: resolve(process.env.GTFS_AWS_S3_URL, join(buildId, 'index.html'))
status: 'Timetable creation completed',
html_download_url: new URL(`/${buildId}/timetables.zip`, process.env.NEXT_PUBLIC_GTFS_AWS_S3_URL),
html_preview_url: new URL(`/${buildId}/index.html`, process.env.NEXT_PUBLIC_GTFS_AWS_S3_URL),
});
}, 1000);
});
Expand Down

0 comments on commit 449ff5b

Please sign in to comment.