mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-15 08:09:31 -07:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0e5018179 | ||
|
|
6422589b5c | ||
|
|
407da90f8a | ||
|
|
3a0e6aa345 | ||
|
|
650dda7b61 | ||
|
|
8f1e8ffb74 | ||
|
|
93af84cbd8 | ||
|
|
117f66e9d0 | ||
|
|
bca9376edc | ||
|
|
8b076db25d | ||
|
|
807932fe3c | ||
|
|
14b1891efd |
@@ -10,8 +10,10 @@ server {
|
||||
|
||||
add_header X-Weatherstar true always;
|
||||
|
||||
include /etc/nginx/includes/wsqs_redirect.conf;
|
||||
|
||||
location / {
|
||||
index redirect.html index.html index.htm;
|
||||
index index.html index.htm;
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "ws4kp",
|
||||
"version": "6.2.3",
|
||||
"version": "6.2.6",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "ws4kp",
|
||||
"version": "6.2.3",
|
||||
"version": "6.2.6",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dotenv": "^17.0.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ws4kp",
|
||||
"version": "6.2.3",
|
||||
"version": "6.2.6",
|
||||
"description": "Welcome to the WeatherStar 4000+ project page!",
|
||||
"main": "index.mjs",
|
||||
"type": "module",
|
||||
|
||||
@@ -106,17 +106,34 @@ const init = async () => {
|
||||
|
||||
// attempt to parse the url parameters
|
||||
const parsedParameters = parseQueryString();
|
||||
const loadFromParsed = parsedParameters.latLonQuery && parsedParameters.latLon;
|
||||
const loadFromParsed = !!parsedParameters.latLon;
|
||||
|
||||
// Auto load the parsed parameters and fall back to the previous query
|
||||
const query = parsedParameters.latLonQuery ?? localStorage.getItem('latLonQuery');
|
||||
const latLon = parsedParameters.latLon ?? localStorage.getItem('latLon');
|
||||
const fromGPS = localStorage.getItem('latLonFromGPS') && !loadFromParsed;
|
||||
|
||||
if (query && latLon && !fromGPS) {
|
||||
if (parsedParameters.latLonQuery && !parsedParameters.latLon) {
|
||||
const txtAddress = document.querySelector(TXT_ADDRESS_SELECTOR);
|
||||
txtAddress.value = query;
|
||||
loadData(JSON.parse(latLon));
|
||||
txtAddress.value = parsedParameters.latLonQuery;
|
||||
const geometry = await geocodeLatLonQuery(parsedParameters.latLonQuery);
|
||||
if (geometry) {
|
||||
doRedirectToGeometry(geometry);
|
||||
}
|
||||
} else if (latLon && !fromGPS) {
|
||||
// update in-page search box if using cached data, or parsed parameter
|
||||
if ((query && !loadFromParsed) || (parsedParameters.latLonQuery && loadFromParsed)) {
|
||||
const txtAddress = document.querySelector(TXT_ADDRESS_SELECTOR);
|
||||
txtAddress.value = query;
|
||||
}
|
||||
// use lat-long lookup if that's all that was provided in the query string
|
||||
if (loadFromParsed && parsedParameters.latLon && !parsedParameters.latLonQuery) {
|
||||
const { lat, lon } = JSON.parse(latLon);
|
||||
getForecastFromLatLon(lat, lon, true);
|
||||
} else {
|
||||
// otherwise use pre-stored data
|
||||
loadData(JSON.parse(latLon));
|
||||
}
|
||||
}
|
||||
if (fromGPS) {
|
||||
btnGetGpsClick();
|
||||
@@ -162,6 +179,26 @@ const init = async () => {
|
||||
document.querySelector('#container').addEventListener('swiped-right', () => swipeCallBack('right'));
|
||||
};
|
||||
|
||||
const geocodeLatLonQuery = async (query) => {
|
||||
try {
|
||||
const data = await json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', {
|
||||
data: {
|
||||
text: query,
|
||||
f: 'json',
|
||||
},
|
||||
});
|
||||
|
||||
const loc = data.locations?.[0];
|
||||
if (loc) {
|
||||
return loc.feature.geometry;
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error('Geocoding failed:', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const autocompleteOnSelect = async (suggestion) => {
|
||||
// Note: it's fine that this uses json instead of safeJson since it's infrequent and user-initiated
|
||||
const data = await json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import STATUS from './status.mjs';
|
||||
import { DateTime, Interval, Duration } from '../vendor/auto/luxon.mjs';
|
||||
import { safeJson } from './utils/fetch.mjs';
|
||||
import { temperature as temperatureUnit, distanceKilometers } from './utils/units.mjs';
|
||||
import { temperature as temperatureUnit, windSpeed as windUnit } from './utils/units.mjs';
|
||||
import { getHourlyIcon } from './icons.mjs';
|
||||
import { directionToNSEW } from './utils/calc.mjs';
|
||||
import WeatherDisplay from './weatherdisplay.mjs';
|
||||
@@ -191,7 +191,7 @@ class Hourly extends WeatherDisplay {
|
||||
const parseForecast = async (data) => {
|
||||
// get unit converters
|
||||
const temperatureConverter = temperatureUnit();
|
||||
const distanceConverter = distanceKilometers();
|
||||
const windConverter = windUnit();
|
||||
|
||||
// parse data
|
||||
const temperature = expand(data.temperature.values);
|
||||
@@ -210,8 +210,8 @@ const parseForecast = async (data) => {
|
||||
temperature: temperatureConverter(temperature[idx]),
|
||||
temperatureUnit: temperatureConverter.units,
|
||||
apparentTemperature: temperatureConverter(apparentTemperature[idx]),
|
||||
windSpeed: distanceConverter(windSpeed[idx]),
|
||||
windUnit: distanceConverter.units,
|
||||
windSpeed: windConverter(windSpeed[idx]),
|
||||
windUnit: windConverter.units,
|
||||
windDirection: directionToNSEW(windDirection[idx]),
|
||||
probabilityOfPrecipitation: probabilityOfPrecipitation[idx],
|
||||
skyCover: skyCover[idx],
|
||||
|
||||
@@ -5,21 +5,22 @@ import en from '../../vendor/auto/locale/en.js';
|
||||
|
||||
// metar-taf-parser requires regex lookbehind
|
||||
// this does not work in iOS < 16.4
|
||||
// this is a detection algorithm for iOS versions
|
||||
const isIos = /iP(ad|od|hone)/i.test(window.navigator.userAgent);
|
||||
let iosVersionOk = false;
|
||||
if (isIos) {
|
||||
// regex match the version string
|
||||
const iosVersionRaw = /OS (\d+)_(\d+)/.exec(window.navigator.userAgent);
|
||||
// check for match
|
||||
if (iosVersionRaw) {
|
||||
// break into parts
|
||||
const iosVersionMajor = parseInt(iosVersionRaw[1], 10);
|
||||
const iosVersionMinor = parseInt(iosVersionRaw[2], 10);
|
||||
if (iosVersionMajor > 16) iosVersionOk = true;
|
||||
if (iosVersionMajor === 16 && iosVersionMinor >= 4) iosVersionOk = true;
|
||||
// this is a detection algorithm for missing lookbehind support
|
||||
const supportsRegexLookAheadLookBehindCheck = () => {
|
||||
try {
|
||||
return (
|
||||
// deliberately using RegExp for broader browser support during check
|
||||
/* eslint-disable prefer-regex-literals */
|
||||
'hibyehihi'
|
||||
.replace(new RegExp('(?<=hi)hi', 'g'), 'hello')
|
||||
.replace(new RegExp('hi(?!bye)', 'g'), 'hey') === 'hibyeheyhello'
|
||||
/* eslint-enable prefer-regex-literals */
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
const supportsRegexLookAheadLookBehind = supportsRegexLookAheadLookBehindCheck();
|
||||
|
||||
/**
|
||||
* Augment observation data by parsing METAR when API fields are missing
|
||||
@@ -27,8 +28,8 @@ if (isIos) {
|
||||
* @returns {Object} - Augmented observation with parsed METAR data filled in
|
||||
*/
|
||||
const augmentObservationWithMetar = (observation) => {
|
||||
// check for a metar message and for unusable ios versions
|
||||
if (!observation?.rawMessage || (isIos && !iosVersionOk)) {
|
||||
// check for a metar message and for regex lookbehind support
|
||||
if (!observation?.rawMessage || (!supportsRegexLookAheadLookBehind)) {
|
||||
return observation;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ url_encode() {
|
||||
|
||||
# build query string from WSQS_ env vars
|
||||
while IFS='=' read -r key val; do
|
||||
# Skip empty lines
|
||||
[ -z "$key" ] && continue
|
||||
|
||||
# Remove WSQS_ prefix and convert underscores to hyphens
|
||||
key="${key#WSQS_}"
|
||||
key="${key//_/-}"
|
||||
@@ -23,11 +26,16 @@ while IFS='=' read -r key val; do
|
||||
QS="${key}=${encoded_val}"
|
||||
fi
|
||||
done << EOF
|
||||
$(env | grep '^WSQS_')
|
||||
$(env | grep '^WSQS_' || true)
|
||||
EOF
|
||||
|
||||
mkdir -p /etc/nginx/includes
|
||||
|
||||
if [ -n "$QS" ]; then
|
||||
# Escape the query string for use in JavaScript (escape backslashes and single quotes)
|
||||
QS_ESCAPED=$(printf '%s' "$QS" | sed "s/\\\\/\\\\\\\\/g; s/'/\\\'/g")
|
||||
|
||||
# Generate redirect.html with JavaScript logic
|
||||
cat > "$ROOT/redirect.html" <<EOF
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
@@ -35,10 +43,36 @@ if [ -n "$QS" ]; then
|
||||
<meta charset="utf-8" />
|
||||
<title>Redirecting</title>
|
||||
<meta http-equiv="refresh" content="0;url=/index.html?$QS" />
|
||||
<script>
|
||||
(function() {
|
||||
var wsqsParams = '$QS_ESCAPED';
|
||||
var currentParams = window.location.search.substring(1);
|
||||
var targetParams = currentParams || wsqsParams;
|
||||
window.location.replace('/index.html?' + targetParams);
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
EOF
|
||||
|
||||
# Generate nginx config for conditional redirects
|
||||
cat > /etc/nginx/includes/wsqs_redirect.conf <<'EOF'
|
||||
location = / {
|
||||
if ($args = '') {
|
||||
rewrite ^ /redirect.html last;
|
||||
}
|
||||
rewrite ^/$ /index.html?$args? redirect;
|
||||
}
|
||||
|
||||
location = /index.html {
|
||||
if ($args = '') {
|
||||
rewrite ^ /redirect.html last;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
else
|
||||
touch /etc/nginx/includes/wsqs_redirect.conf
|
||||
fi
|
||||
|
||||
exec nginx -g 'daemon off;'
|
||||
|
||||
@@ -73,7 +73,10 @@
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "explicit"
|
||||
}
|
||||
},
|
||||
"cSpell.words": [
|
||||
"hibyehihi"
|
||||
]
|
||||
},
|
||||
"extensions": {
|
||||
"recommendations": [
|
||||
|
||||
Reference in New Issue
Block a user