Skip to content

Commit

Permalink
fix(CNX-8322): Separated completely frontend2 parsing (#59)
Browse files Browse the repository at this point in the history
* fix: Separated completely frontend2 parsing

This prevents logic from Fe2 leaking into Fe1 and viceversa, which could cause `null` exceptions in some cases.

* CNX-8322 Track in Jira
  • Loading branch information
AlanRynne authored Nov 30, 2023
1 parent 9a5c128 commit 95f51b0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- run:
name: "Publish Release on GitHub"
command: |
ghr -t ${GH_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${CIRCLE_TAG} ./bin/
ghr -t ${GH_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${CIRCLE_TAG} ./bin/Speckle.mez
workflows:
build:
jobs:
Expand Down
69 changes: 45 additions & 24 deletions speckle/helpers/ParseStreamUrl.pqm
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,61 @@ let
Message.Format = "Loading '#{0}' failed - '#{1}': '#{2}'",
Message.Parameters = {fileName, e[Reason], e[Message]},
Detail = [File = fileName, Error = e]
]
in
(url as text) as record =>
],
IsFe2Url = (segments as list) as logical => List.Count(segments) = 4 and segments{2} = "models",
GetUrlType = (branchName as nullable text, commitId as nullable text, objectId as nullable text) as text =>
if (commitId <> null) then
"Commit"
else if (objectId <> null) then
"Object"
else if (branchName <> null) then
"Branch"
else
"Stream",
ParseFe1Url = (server as text, segments as list) as record =>
let
// Get server and streamId, and branchName / commitId / objectid from the input url
server = Text.Combine({Uri.Parts(url)[Scheme], "://", Uri.Parts(url)[Host]}),
segments = Text.Split(Text.AfterDelimiter(Uri.Parts(url)[Path], "/", 0), "/"),
streamId = segments{1},
modelList = if (List.Count(segments) = 4 and segments{2} = "models") then segments{3} else null,
branchName = if (List.Count(segments) = 4 and segments{2} = "branches") then segments{3} else null,
commitId = if (List.Count(segments) = 4 and segments{2} = "commits") then segments{3} else null,
objectId = if (List.Count(segments) = 4 and segments{2} = "objects") then segments{3} else null,
urlType = GetUrlType(branchName, commitId, objectId)
in
[
urlType = urlType,
server = server as text,
id = streamId as nullable text,
branch = branchName as nullable text,
commit = commitId as nullable text,
object = objectId as nullable text
],
ParseFe2Url = (server as text, segments as list) as record =>
let
streamId = segments{1},
modelList = segments{3},
firstModel = Text.Split(modelList, ","){0},
modelAndVersion = Text.Split(firstModel, "@"),
modelId = modelAndVersion{0},
versionId = if (List.Count(modelAndVersion) > 1) then modelAndVersion{1} else null,
model = if (modelId <> null) then GetModel(server, streamId, modelId) else null,
branchName = if (List.Count(segments) = 4 and segments{2} = "branches") then segments{3} else null,
commitId = if (List.Count(segments) = 4 and segments{2} = "commits") then segments{3} else null,
objectId = if (List.Count(segments) = 4 and segments{2} = "objects") then segments{3} else null,
modelOrBranchName = if (model <> null) then model[name] else branchName,
commitOrVersion = if (versionId <> null) then versionId else commitId,
urlType =
if (commitOrVersion <> null) then
"Commit"
else if (objectId <> null) then
"Object"
else if (modelOrBranchName <> null) then
"Branch"
else
"Stream"
urlType = GetUrlType(model[name], versionId, null)
in
[
urlType = urlType,
server = server,
id = streamId,
branch = modelOrBranchName,
commit = commitOrVersion,
object = objectId
branch = model[name],
commit = versionId,
object = null
]
in
(url as text) as record =>
let
// Get server and streamId, and branchName / commitId / objectid from the input url
server = Text.Combine({Uri.Parts(url)[Scheme], "://", Uri.Parts(url)[Host]}),
segments = Text.Split(Text.AfterDelimiter(Uri.Parts(url)[Path], "/", 0), "/"),
isFe2 = IsFe2Url(segments)
in
if (isFe2) then
ParseFe2Url(server, segments)
else
ParseFe1Url(server, segments)

0 comments on commit 95f51b0

Please sign in to comment.