Replacing shared by to
This commit is contained in:
parent
acb6156ed2
commit
f07bf07c3f
|
@ -80,7 +80,7 @@ const prune = (
|
|||
},
|
||||
extensions: any,
|
||||
docs: any[],
|
||||
shared: string[]
|
||||
to: string[]
|
||||
) => {
|
||||
if (typeof object === 'object') {
|
||||
for (const key in object) {
|
||||
|
@ -126,14 +126,14 @@ const prune = (
|
|||
docs.push({
|
||||
_id: getUri(key, subId),
|
||||
type: key,
|
||||
shared,
|
||||
to,
|
||||
origin: state().remoteUrl,
|
||||
doc: subObjects[index],
|
||||
});
|
||||
prune(subId, subObjects[index], previousIds, {}, docs, shared);
|
||||
prune(subId, subObjects[index], previousIds, {}, docs, to);
|
||||
}
|
||||
object[key] = undefined;
|
||||
} else prune(id, object[key], previousIds, extensions, docs, shared);
|
||||
} else prune(id, object[key], previousIds, extensions, docs, to);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -187,7 +187,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => {
|
|||
};
|
||||
convertTrkToRteWhenNeeded(gpx);
|
||||
let previousGpx: Gpx | null = null;
|
||||
let shared: string[];
|
||||
let to: string[];
|
||||
if (id === 'new') {
|
||||
const currentDateTime = new Date().toISOString();
|
||||
const startTime = new Date(findStartTime(gpx, currentDateTime));
|
||||
|
@ -204,7 +204,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => {
|
|||
type: 'gpx',
|
||||
origin: state().remoteUrl,
|
||||
doc: gpx,
|
||||
// a new GPX isn't shared...
|
||||
// a new GPX isn't to...
|
||||
},
|
||||
{
|
||||
_id: getUri('extensions', gpxId),
|
||||
|
@ -216,8 +216,8 @@ export const pruneAndSaveImportedGpx = async (params: any) => {
|
|||
} else {
|
||||
gpxId = getUri('gpx', id);
|
||||
previousGpx = (await getGpx({ id })) ?? null;
|
||||
if (previousGpx?.extensions?.shared) {
|
||||
shared = previousGpx?.extensions?.shared.split(/\s*,\s*/);
|
||||
if (previousGpx?.extensions?.to) {
|
||||
to = previousGpx?.extensions?.to.split(/\s*,\s*/);
|
||||
}
|
||||
console.log({
|
||||
caller: 'pruneAndSaveImportedGpx / previousGpx',
|
||||
|
@ -249,7 +249,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => {
|
|||
const trkId = getUri('trk', trkUri);
|
||||
previousIds.trk = trkId.trk;
|
||||
}
|
||||
prune(gpxId, gpx, previousIds, extensions, docs, shared);
|
||||
prune(gpxId, gpx, previousIds, extensions, docs, to);
|
||||
console.log({ caller: 'pruneAndSaveImportedGpx / pruned', docs });
|
||||
try {
|
||||
const result = await putAll(docs);
|
||||
|
@ -430,12 +430,12 @@ export const putGpx = async (params: any) => {
|
|||
});
|
||||
}
|
||||
|
||||
let previousShared;
|
||||
let previousTo;
|
||||
try {
|
||||
previousShared = (await get(`${id}/4extensions`)).doc?.shared;
|
||||
previousTo = (await get(`${id}/4extensions`)).doc?.to;
|
||||
} catch (error) {}
|
||||
|
||||
console.log({ caller: 'putGpx', params, id, gpx, previousShared });
|
||||
console.log({ caller: 'putGpx', params, id, gpx, previousTo });
|
||||
const extensions = gpx?.extensions;
|
||||
|
||||
gpx.extensions = undefined;
|
||||
|
@ -460,19 +460,19 @@ export const putGpx = async (params: any) => {
|
|||
}
|
||||
}
|
||||
|
||||
if (previousShared !== extensions?.shared) {
|
||||
const shared = extensions?.shared.split(/\s*,\s*/);
|
||||
if (previousTo !== extensions?.to) {
|
||||
const to = extensions?.to.split(/\s*,\s*/);
|
||||
const family = (await getFamily(id, { include_docs: true })).rows.map(
|
||||
(row: any) => {
|
||||
return { ...row.doc, shared };
|
||||
return { ...row.doc, to };
|
||||
}
|
||||
);
|
||||
console.log({
|
||||
caller: 'putGpx / updateShared',
|
||||
caller: 'putGpx / updateTo',
|
||||
params,
|
||||
id,
|
||||
gpx,
|
||||
previousShared,
|
||||
previousTo,
|
||||
family,
|
||||
});
|
||||
await db.bulkDocs(family);
|
||||
|
|
|
@ -21,20 +21,20 @@ export const put = async (
|
|||
current = await targetDb.get(_id);
|
||||
} catch {
|
||||
const parentId = getParentId(_id);
|
||||
let shared;
|
||||
let to;
|
||||
try {
|
||||
const parent = await db.get(parentId);
|
||||
// console.log({ caller: 'put', parent });
|
||||
shared = parent.shared;
|
||||
to = parent.to;
|
||||
} catch {}
|
||||
current = { _rev: undefined, shared, doc: cloneDeep(defaultDoc) };
|
||||
current = { _rev: undefined, to, doc: cloneDeep(defaultDoc) };
|
||||
}
|
||||
try {
|
||||
putDoc = {
|
||||
_id,
|
||||
_rev: current._rev,
|
||||
type,
|
||||
shared: current.shared,
|
||||
to: current.to,
|
||||
origin: current.origin ?? state().remoteUrl,
|
||||
doc: update(current.doc),
|
||||
};
|
||||
|
|
|
@ -50,7 +50,7 @@ interface Extensions {
|
|||
'dyo:useragent'?: string;
|
||||
'dyo:minZoom'?: number;
|
||||
address?: any;
|
||||
shared?: string;
|
||||
to?: string;
|
||||
}
|
||||
|
||||
interface Trk {
|
||||
|
|
Loading…
Reference in New Issue