Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c45f7fb6
Commit
c45f7fb6
authored
Jul 09, 2021
by
Denys Mishunov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix-webide' into 'master'
Fix WebIDE image being base64 See merge request gitlab-org/gitlab!65165
parents
9ea90adf
89256d4d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
10 deletions
+15
-10
app/assets/javascripts/ide/components/repo_editor.vue
app/assets/javascripts/ide/components/repo_editor.vue
+5
-1
app/assets/javascripts/ide/stores/actions.js
app/assets/javascripts/ide/stores/actions.js
+2
-2
app/assets/javascripts/ide/stores/utils.js
app/assets/javascripts/ide/stores/utils.js
+2
-2
spec/frontend/ide/components/repo_editor_spec.js
spec/frontend/ide/components/repo_editor_spec.js
+3
-2
spec/frontend/ide/stores/utils_spec.js
spec/frontend/ide/stores/utils_spec.js
+3
-3
No files found.
app/assets/javascripts/ide/components/repo_editor.vue
View file @
c45f7fb6
...
...
@@ -415,7 +415,11 @@ export default {
const
parentPath
=
getPathParent
(
this
.
file
.
path
);
const
path
=
`
${
parentPath
?
`
${
parentPath
}
/`
:
''
}${
file
.
name
}
`
;
return
this
.
addTempImage
({
name
:
path
,
rawPath
:
content
}).
then
(({
name
:
fileName
})
=>
{
return
this
.
addTempImage
({
name
:
path
,
rawPath
:
URL
.
createObjectURL
(
file
),
content
:
atob
(
content
.
split
(
'
base64,
'
)[
1
]),
}).
then
(({
name
:
fileName
})
=>
{
this
.
editor
.
replaceSelectedText
(
`![
${
fileName
}
](./
${
fileName
}
)`
);
});
});
...
...
app/assets/javascripts/ide/stores/actions.js
View file @
c45f7fb6
...
...
@@ -76,11 +76,11 @@ export const createTempEntry = (
return
file
;
};
export
const
addTempImage
=
({
dispatch
,
getters
},
{
name
,
rawPath
=
''
})
=>
export
const
addTempImage
=
({
dispatch
,
getters
},
{
name
,
rawPath
=
''
,
content
=
''
})
=>
dispatch
(
'
createTempEntry
'
,
{
name
:
getters
.
getAvailableFileName
(
name
),
type
:
'
blob
'
,
content
:
rawPath
.
split
(
'
base64,
'
)[
1
]
,
content
,
rawPath
,
openFile
:
false
,
makeFileActive
:
false
,
...
...
app/assets/javascripts/ide/stores/utils.js
View file @
c45f7fb6
...
...
@@ -252,10 +252,10 @@ export function extractMarkdownImagesFromEntries(mdFile, entries) {
.
trim
();
const
imageContent
=
entries
[
imagePath
]?.
content
||
entries
[
imagePath
]?.
raw
;
const
imageRawPath
=
entries
[
imagePath
]?.
rawPath
;
if
(
!
isAbsolute
(
path
)
&&
imageContent
)
{
const
ext
=
path
.
includes
(
'
.
'
)
?
path
.
split
(
'
.
'
).
pop
().
trim
()
:
'
jpeg
'
;
const
src
=
`data:image/
${
ext
}
;base64,
${
imageContent
}
`
;
const
src
=
imageRawPath
;
i
+=
1
;
const
key
=
`{{
${
prefix
}${
i
}
}}`
;
images
[
key
]
=
{
alt
,
src
,
title
};
...
...
spec/frontend/ide/components/repo_editor_spec.js
View file @
c45f7fb6
...
...
@@ -640,11 +640,12 @@ describe('RepoEditor', () => {
pasteImage
();
await
waitForFileContentChange
();
expect
(
vm
.
$store
.
state
.
entries
[
'
foo/foo.png
'
].
rawPath
.
startsWith
(
'
blob:
'
)).
toBe
(
true
);
expect
(
vm
.
$store
.
state
.
entries
[
'
foo/foo.png
'
]).
toMatchObject
({
path
:
'
foo/foo.png
'
,
type
:
'
blob
'
,
content
:
'
Zm9v
'
,
rawPath
:
'
data:image/png;base64,Zm9v
'
,
content
:
'
foo
'
,
rawPath
:
vm
.
$store
.
state
.
entries
[
'
foo/foo.png
'
].
rawPath
,
});
});
...
...
spec/frontend/ide/stores/utils_spec.js
View file @
c45f7fb6
...
...
@@ -604,7 +604,7 @@ describe('Multi-file store utils', () => {
let
entries
;
beforeEach
(()
=>
{
const
img
=
{
content
:
'
/base64/encoded/image+
'
};
const
img
=
{
content
:
'
png-gibberish
'
,
rawPath
:
'
blob:1234
'
};
mdFile
=
{
path
:
'
path/to/some/directory/myfile.md
'
};
entries
=
{
// invalid (or lack of) extensions are also supported as long as there's
...
...
@@ -637,14 +637,14 @@ describe('Multi-file store utils', () => {
${
'
* ![img](img.png "title here")
'
}
|
${
'
png
'
}
|
${
'
img
'
}
|
${
'
title here
'
}
`
(
'
correctly transforms markdown with uncommitted images: $markdownBefore
'
,
({
markdownBefore
,
ext
,
imgAlt
,
imgTitle
})
=>
{
({
markdownBefore
,
imgAlt
,
imgTitle
})
=>
{
mdFile
.
content
=
markdownBefore
;
expect
(
utils
.
extractMarkdownImagesFromEntries
(
mdFile
,
entries
)).
toEqual
({
content
:
'
* {{gl_md_img_1}}
'
,
images
:
{
'
{{gl_md_img_1}}
'
:
{
src
:
`data:image/
${
ext
}
;base64,/base64/encoded/image+`
,
src
:
'
blob:1234
'
,
alt
:
imgAlt
,
title
:
imgTitle
,
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment