mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 22:33:24 +00:00
Handle saved builds and old URLs
This commit is contained in:
@@ -90,7 +90,7 @@ export default class Coriolis extends React.Component {
|
||||
r.params.code = ship.toString();
|
||||
this._setPage(OutfittingPage, r);
|
||||
} catch (err) {
|
||||
this._onError("Failed to import ship", r.path, 0, 0, err);
|
||||
this._onError('Failed to import ship', r.path, 0, 0, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import PowerManagement from '../components/PowerManagement';
|
||||
import CostSection from '../components/CostSection';
|
||||
import ModalExport from '../components/ModalExport';
|
||||
import Slider from '../components/Slider';
|
||||
import * as Utils from '../utils/UtilityFunctions';
|
||||
|
||||
const SPEED_SERIES = ['boost', '4 Pips', '2 Pips', '0 Pips'];
|
||||
const SPEED_COLORS = ['#0088d2', '#ff8c0d', '#D26D00', '#c06400'];
|
||||
@@ -58,7 +59,7 @@ export default class OutfittingPage extends Page {
|
||||
_initState(context) {
|
||||
let params = context.route.params;
|
||||
let shipId = params.ship;
|
||||
let code = params.code;
|
||||
let code = Utils.fromUrlSafe(params.code);
|
||||
let buildName = params.bn;
|
||||
let data = Ships[shipId]; // Retrieve the basic ship properties, slots and defaults
|
||||
let savedCode = Persist.getBuild(shipId, buildName);
|
||||
|
||||
@@ -596,21 +596,23 @@ export default class Ship {
|
||||
hardpoints = new Array(this.hardpoints.length),
|
||||
internal = new Array(this.internal.length),
|
||||
modifications = new Array(1 + this.standard.length + this.hardpoints.length + this.internal.length),
|
||||
parts = serializedString.split('.'),
|
||||
// Although we un-UrlSafe the serialized string when it comes in as a URL old code used to url-encode
|
||||
// the build before it was written to local store so we do it again here to catch that situation
|
||||
parts = Utils.fromUrlSafe(serializedString).split('.'),
|
||||
priorities = null,
|
||||
enabled = null,
|
||||
code = parts[0];
|
||||
|
||||
if (parts[1]) {
|
||||
enabled = Utils.fromUrlSafe(LZString.decompressFromBase64(parts[1])).split('');
|
||||
enabled = LZString.decompressFromBase64(parts[1]).split('');
|
||||
}
|
||||
|
||||
if (parts[2]) {
|
||||
priorities = Utils.fromUrlSafe(LZString.decompressFromBase64(parts[2])).split('');
|
||||
priorities = LZString.decompressFromBase64(parts[2]).split('');
|
||||
}
|
||||
|
||||
if (parts[3]) {
|
||||
const modstr = Utils.fromUrlSafe(parts[3]);
|
||||
const modstr = parts[3];
|
||||
if (modstr.match(':')) {
|
||||
this.decodeModificationsString(modstr, modifications);
|
||||
} else {
|
||||
@@ -1199,7 +1201,7 @@ export default class Ship {
|
||||
priorities.push(slot.priority);
|
||||
}
|
||||
|
||||
this.serialized.priorities = Utils.toUrlSafe(LZString.compressToBase64(priorities.join('')));
|
||||
this.serialized.priorities = LZString.compressToBase64(priorities.join(''));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1220,7 +1222,7 @@ export default class Ship {
|
||||
enabled.push(slot.enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
this.serialized.enabled = Utils.toUrlSafe(LZString.compressToBase64(enabled.join('')));
|
||||
this.serialized.enabled = LZString.compressToBase64(enabled.join(''));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1266,7 +1268,7 @@ export default class Ship {
|
||||
}
|
||||
allMods.push(slotMods.join(';'));
|
||||
}
|
||||
this.serialized.modifications = Utils.toUrlSafe(LZString.compressToBase64(allMods.join(',').replace(/,+$/, '')));
|
||||
this.serialized.modifications = LZString.compressToBase64(allMods.join(',').replace(/,+$/, ''));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1387,7 +1389,7 @@ export default class Ship {
|
||||
buffer.writeInt8(-1, curpos++);
|
||||
}
|
||||
|
||||
this.serialized.modifications = Utils.toUrlSafe(zlib.gzipSync(buffer).toString('base64'));
|
||||
this.serialized.modifications = zlib.gzipSync(buffer).toString('base64');
|
||||
} else {
|
||||
this.serialized.modifications = null;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as Utils from './/UtilityFunctions';
|
||||
|
||||
/**
|
||||
* Generates a URL for the outiffing page
|
||||
@@ -10,7 +11,7 @@ export function outfitURL(shipId, code, buildName) {
|
||||
let parts = ['/outfit/', shipId];
|
||||
|
||||
if (code) {
|
||||
parts.push('/', code);
|
||||
parts.push('/', Utils.toUrlSafe(code));
|
||||
}
|
||||
|
||||
if (buildName) {
|
||||
|
||||
@@ -65,7 +65,7 @@ export function shallowEqual(objA, objB) {
|
||||
* @return {string} the converted string
|
||||
*/
|
||||
export function toUrlSafe(data) {
|
||||
return data.replace(/\//g, '-').replace(/\+/g, '_');
|
||||
return data ? data.replace(/\//g, '-').replace(/\+/g, '_') : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,5 +74,5 @@ export function toUrlSafe(data) {
|
||||
* @return {string} the converted string
|
||||
*/
|
||||
export function fromUrlSafe(data) {
|
||||
return data.replace(/-/g, '/').replace(/_/g, '+');
|
||||
return data ? data.replace(/-/g, '/').replace(/_/g, '+') : null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user