Skip to content

Commit 9ed3175

Browse files
authored
256 import creates bad ids (#257)
* correct id for new Layers * set _id on imported project * Update Layer.js
1 parent 629447e commit 9ed3175

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

classes/Layer/Layer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ export default class Layer {
3636

3737
// Static Methods
3838
static build(projectId, label, canvases, projectLabel = "Default") {
39-
let thisLayer = {}
40-
projectId ??= database.reserveId()
41-
thisLayer.projectId = projectId
42-
thisLayer.label = label ?? `${projectLabel} - Layer ${Date.now()}`
43-
4439
if (!Array.isArray(canvases)) {
4540
if (!canvases) {
4641
throw new Error("At least one Canvas must be included.")
4742
}
4843
canvases = [canvases]
4944
}
50-
thisLayer.id = `${process.env.SERVERURL}layer/${databaseTiny.reserveId()}`
45+
46+
const thisLayer = {
47+
projectId,
48+
label: label ?? `${projectLabel} - Layer ${Date.now()}`,
49+
id: `${process.env.SERVERURL}project/${projectId.split('/').pop()}/layer/${databaseTiny.reserveId()}`
50+
}
5151
const pages = canvases.map(c => Page.build(projectId, thisLayer.id, c).asProjectPage())
5252
pages.forEach((page, index) => {
5353
if (index > 0) page.prev = pages[index - 1].id

classes/Project/Project.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export default class Project {
2929
payload._createdAt ??= Date.now().toString().slice(-6)
3030
payload._modifiedAt ??= -1
3131
payload._lastModified ??= payload.layers?.[0]?.pages?.[0]?.id ?? true
32-
console.log("Creating project...", payload.layers)
3332
try {
3433
return database.save(payload, "projects")
3534
} catch (err) {

classes/Project/ProjectFactory.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,17 @@ export default class ProjectFactory {
9999
message: err.message ?? "No manifest found. Cannot process empty object"
100100
}
101101
}
102+
const _id = database.reserveId()
102103
const now = Date.now().toString().slice(-6)
103104
const label = ProjectFactory.getLabelAsString(manifest.label) ?? now
104105
const metadata = manifest.metadata ?? []
105-
const layer = Layer.build( database.reserveId(), `First Layer - ${label}`, manifest.items )
106+
const layer = Layer.build( _id, `First Layer - ${label}`, manifest.items )
106107

107108
const firstPage = layer.pages[0]?.id ?? true
108109

109110
// required properties: id, label, metadata, manifest, layers
110111
return {
112+
_id,
111113
label,
112114
metadata,
113115
manifest: [ manifest.id ],

0 commit comments

Comments
 (0)