Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions classes/Layer/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ export default class Layer {

// Static Methods
static build(projectId, label, canvases, projectLabel = "Default") {
let thisLayer = {}
projectId ??= database.reserveId()
thisLayer.projectId = projectId
thisLayer.label = label ?? `${projectLabel} - Layer ${Date.now()}`

if (!Array.isArray(canvases)) {
if (!canvases) {
throw new Error("At least one Canvas must be included.")
}
canvases = [canvases]
}
thisLayer.id = `${process.env.SERVERURL}layer/${databaseTiny.reserveId()}`

const thisLayer = {
projectId,
label: label ?? `${projectLabel} - Layer ${Date.now()}`,
id: `${process.env.SERVERURL}project/${projectId.split('/').pop()}/layer/${databaseTiny.reserveId()}`
}
const pages = canvases.map(c => Page.build(projectId, thisLayer.id, c).asProjectPage())
pages.forEach((page, index) => {
if (index > 0) page.prev = pages[index - 1].id
Expand Down
1 change: 0 additions & 1 deletion classes/Project/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default class Project {
payload._createdAt ??= Date.now().toString().slice(-6)
payload._modifiedAt ??= -1
payload._lastModified ??= payload.layers?.[0]?.pages?.[0]?.id ?? true
console.log("Creating project...", payload.layers)
try {
return database.save(payload, "projects")
} catch (err) {
Expand Down
4 changes: 3 additions & 1 deletion classes/Project/ProjectFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ export default class ProjectFactory {
message: err.message ?? "No manifest found. Cannot process empty object"
}
}
const _id = database.reserveId()
const now = Date.now().toString().slice(-6)
const label = ProjectFactory.getLabelAsString(manifest.label) ?? now
const metadata = manifest.metadata ?? []
const layer = Layer.build( database.reserveId(), `First Layer - ${label}`, manifest.items )
const layer = Layer.build( _id, `First Layer - ${label}`, manifest.items )

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

// required properties: id, label, metadata, manifest, layers
return {
_id,
label,
metadata,
manifest: [ manifest.id ],
Expand Down
Loading