Vite + TypeScript PWA that mirrors the Android app's core features: - Pre-processed shelter data (build-time UTM33N→WGS84 conversion) - Leaflet map with shelter markers, user location, and offline tiles - Canvas compass arrow (ported from DirectionArrowView.kt) - IndexedDB shelter cache with 7-day staleness check - Service worker with CacheFirst tiles and precached app shell - i18n for en, nb, nn (ported from Android strings.xml) - iOS/Android compass handling with low-pass filter - Respects user map interaction (no auto-snap on pan/zoom) - Build revision cache-breaker for reliable SW updates Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
'use strict'
|
|
|
|
const u = require('universalify').fromCallback
|
|
const path = require('path')
|
|
const fs = require('graceful-fs')
|
|
const mkdir = require('../mkdirs')
|
|
const pathExists = require('../path-exists').pathExists
|
|
|
|
function createLink (srcpath, dstpath, callback) {
|
|
function makeLink (srcpath, dstpath) {
|
|
fs.link(srcpath, dstpath, err => {
|
|
if (err) return callback(err)
|
|
callback(null)
|
|
})
|
|
}
|
|
|
|
pathExists(dstpath, (err, destinationExists) => {
|
|
if (err) return callback(err)
|
|
if (destinationExists) return callback(null)
|
|
fs.lstat(srcpath, (err) => {
|
|
if (err) {
|
|
err.message = err.message.replace('lstat', 'ensureLink')
|
|
return callback(err)
|
|
}
|
|
|
|
const dir = path.dirname(dstpath)
|
|
pathExists(dir, (err, dirExists) => {
|
|
if (err) return callback(err)
|
|
if (dirExists) return makeLink(srcpath, dstpath)
|
|
mkdir.mkdirs(dir, err => {
|
|
if (err) return callback(err)
|
|
makeLink(srcpath, dstpath)
|
|
})
|
|
})
|
|
})
|
|
})
|
|
}
|
|
|
|
function createLinkSync (srcpath, dstpath) {
|
|
const destinationExists = fs.existsSync(dstpath)
|
|
if (destinationExists) return undefined
|
|
|
|
try {
|
|
fs.lstatSync(srcpath)
|
|
} catch (err) {
|
|
err.message = err.message.replace('lstat', 'ensureLink')
|
|
throw err
|
|
}
|
|
|
|
const dir = path.dirname(dstpath)
|
|
const dirExists = fs.existsSync(dir)
|
|
if (dirExists) return fs.linkSync(srcpath, dstpath)
|
|
mkdir.mkdirsSync(dir)
|
|
|
|
return fs.linkSync(srcpath, dstpath)
|
|
}
|
|
|
|
module.exports = {
|
|
createLink: u(createLink),
|
|
createLinkSync
|
|
}
|