Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Goessmann
logging-scratch-gui
Commits
09725f58
Commit
09725f58
authored
6 years ago
by
Paul Kaplan
Browse files
Options
Downloads
Patches
Plain Diff
Send snapshots from the renderer to be saved as project thumbnails
parent
bcca5bf1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib/data-uri-to-blob.js
+17
-0
17 additions, 0 deletions
src/lib/data-uri-to-blob.js
src/lib/project-saver-hoc.jsx
+29
-0
29 additions, 0 deletions
src/lib/project-saver-hoc.jsx
with
46 additions
and
0 deletions
src/lib/data-uri-to-blob.js
0 → 100644
+
17
−
0
View file @
09725f58
/**
* Utility to convert data URIs to blobs
* Adapted from https://stackoverflow.com/questions/12168909/blob-from-dataurl
* @param {string} dataURI the data uri to blobify
* @return {Blob} a blob representing the data uri
*/
export
default
function
dataURItoBlob
(
dataURI
)
{
const
byteString
=
atob
(
dataURI
.
split
(
'
,
'
)[
1
]);
const
mimeString
=
dataURI
.
split
(
'
,
'
)[
0
].
split
(
'
:
'
)[
1
].
split
(
'
;
'
)[
0
];
const
arrayBuffer
=
new
ArrayBuffer
(
byteString
.
length
);
const
uintArray
=
new
Uint8Array
(
arrayBuffer
);
for
(
let
i
=
0
;
i
<
byteString
.
length
;
i
++
)
{
uintArray
[
i
]
=
byteString
.
charCodeAt
(
i
);
}
const
blob
=
new
Blob
([
arrayBuffer
],
{
type
:
mimeString
});
return
blob
;
}
This diff is collapsed.
Click to expand it.
src/lib/project-saver-hoc.jsx
+
29
−
0
View file @
09725f58
...
...
@@ -6,6 +6,8 @@ import VM from 'scratch-vm';
import
log
from
'
../lib/log
'
;
import
storage
from
'
../lib/storage
'
;
import
dataURItoBlob
from
'
../lib/data-uri-to-blob
'
;
import
{
showAlertWithTimeout
,
showStandardAlert
...
...
@@ -204,11 +206,36 @@ const ProjectSaverHOC = function (WrappedComponent) {
return
response
;
});
})
.
then
(
response
=>
{
const
id
=
response
.
id
.
toString
();
if
(
id
&&
this
.
props
.
onUpdateProjectThumbnail
)
{
this
.
storeProjectThumbnail
(
id
);
}
})
.
catch
(
err
=>
{
log
.
error
(
err
);
throw
err
;
// pass the error up the chain
});
}
/**
* Store a snapshot of the project once it has been saved/created.
* Needs to happen _after_ save because the project must have an ID.
* @param {!string} projectId - id of the project, must be defined.
*/
storeProjectThumbnail
(
projectId
)
{
try
{
this
.
props
.
vm
.
renderer
.
requestSnapshot
(
dataURI
=>
{
this
.
props
.
onUpdateProjectThumbnail
(
projectId
,
dataURItoBlob
(
dataURI
));
});
}
catch
(
e
)
{
log
.
error
(
'
Project thumbnail save error
'
,
e
);
// This is intentionally fire/forget because a failure
// to save the thumbnail is not vitally important to the user.
}
}
render
()
{
const
{
/* eslint-disable no-unused-vars */
...
...
@@ -233,6 +260,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
onShowSaveSuccessAlert
,
onShowSavingAlert
,
onUpdatedProject
,
onUpdateProjectThumbnail
,
reduxProjectId
,
reduxProjectTitle
,
setAutoSaveTimeoutId
:
setAutoSaveTimeoutIdProp
,
...
...
@@ -270,6 +298,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
onShowCreatingAlert
:
PropTypes
.
func
,
onShowSaveSuccessAlert
:
PropTypes
.
func
,
onShowSavingAlert
:
PropTypes
.
func
,
onUpdateProjectThumbnail
:
PropTypes
.
func
,
onUpdatedProject
:
PropTypes
.
func
,
projectChanged
:
PropTypes
.
bool
,
reduxProjectId
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
number
]),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment