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
e28237cf
Commit
e28237cf
authored
Aug 10, 2021
by
Himanshu Kapoor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename parseFilename and add comments
parent
86ee3478
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
11 deletions
+21
-11
app/assets/javascripts/content_editor/components/toolbar_image_button.vue
...cripts/content_editor/components/toolbar_image_button.vue
+2
-2
app/assets/javascripts/content_editor/services/upload_helpers.js
...ets/javascripts/content_editor/services/upload_helpers.js
+3
-3
app/assets/javascripts/content_editor/services/utils.js
app/assets/javascripts/content_editor/services/utils.js
+12
-2
spec/frontend/content_editor/extensions/attachment_spec.js
spec/frontend/content_editor/extensions/attachment_spec.js
+4
-4
No files found.
app/assets/javascripts/content_editor/components/toolbar_image_button.vue
View file @
e28237cf
...
@@ -9,7 +9,7 @@ import {
...
@@ -9,7 +9,7 @@ import {
GlTooltipDirective
as
GlTooltip
,
GlTooltipDirective
as
GlTooltip
,
}
from
'
@gitlab/ui
'
;
}
from
'
@gitlab/ui
'
;
import
{
acceptedMimes
}
from
'
../services/upload_helpers
'
;
import
{
acceptedMimes
}
from
'
../services/upload_helpers
'
;
import
{
parse
Filename
}
from
'
../services/utils
'
;
import
{
extract
Filename
}
from
'
../services/utils
'
;
export
default
{
export
default
{
components
:
{
components
:
{
...
@@ -41,7 +41,7 @@ export default {
...
@@ -41,7 +41,7 @@ export default {
.
setImage
({
.
setImage
({
src
:
this
.
imgSrc
,
src
:
this
.
imgSrc
,
canonicalSrc
:
this
.
imgSrc
,
canonicalSrc
:
this
.
imgSrc
,
alt
:
parse
Filename
(
this
.
imgSrc
),
alt
:
extract
Filename
(
this
.
imgSrc
),
})
})
.
run
();
.
run
();
...
...
app/assets/javascripts/content_editor/services/upload_helpers.js
View file @
e28237cf
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
__
}
from
'
~/locale
'
;
import
{
__
}
from
'
~/locale
'
;
import
{
parse
Filename
,
readFileAsDataURL
}
from
'
./utils
'
;
import
{
extract
Filename
,
readFileAsDataURL
}
from
'
./utils
'
;
export
const
acceptedMimes
=
{
export
const
acceptedMimes
=
{
image
:
[
'
image/jpeg
'
,
'
image/png
'
,
'
image/gif
'
,
'
image/jpg
'
],
image
:
[
'
image/jpeg
'
,
'
image/png
'
,
'
image/gif
'
,
'
image/jpg
'
],
...
@@ -66,7 +66,7 @@ const uploadImage = async ({ editor, file, uploadsPath, renderMarkdown }) => {
...
@@ -66,7 +66,7 @@ const uploadImage = async ({ editor, file, uploadsPath, renderMarkdown }) => {
tr
.
setNodeMarkup
(
position
,
undefined
,
{
tr
.
setNodeMarkup
(
position
,
undefined
,
{
uploading
:
false
,
uploading
:
false
,
src
:
encodedSrc
,
src
:
encodedSrc
,
alt
:
parse
Filename
(
src
),
alt
:
extract
Filename
(
src
),
canonicalSrc
,
canonicalSrc
,
}),
}),
);
);
...
@@ -81,7 +81,7 @@ const uploadAttachment = async ({ editor, file, uploadsPath, renderMarkdown }) =
...
@@ -81,7 +81,7 @@ const uploadAttachment = async ({ editor, file, uploadsPath, renderMarkdown }) =
const
{
view
}
=
editor
;
const
{
view
}
=
editor
;
const
text
=
parse
Filename
(
file
.
name
);
const
text
=
extract
Filename
(
file
.
name
);
const
{
state
}
=
view
;
const
{
state
}
=
view
;
const
{
from
}
=
state
.
selection
;
const
{
from
}
=
state
.
selection
;
...
...
app/assets/javascripts/content_editor/services/utils.js
View file @
e28237cf
...
@@ -4,8 +4,18 @@ export const hasSelection = (tiptapEditor) => {
...
@@ -4,8 +4,18 @@ export const hasSelection = (tiptapEditor) => {
return
from
<
to
;
return
from
<
to
;
};
};
export
const
parseFilename
=
(
src
)
=>
{
/**
return
src
.
replace
(
/^.*
\/
|
\.
.+
?
$/g
,
''
).
replace
(
/
\W
+/g
,
'
'
);
* Extracts filename from a URL
*
* @example
* > extractFilename('https://gitlab.com/images/logo-full.png')
* < 'logo-full'
*
* @param {string} src The URL to extract filename from
* @returns {string}
*/
export
const
extractFilename
=
(
src
)
=>
{
return
src
.
replace
(
/^.*
\/
|
\.
.+
?
$/g
,
''
);
};
};
export
const
readFileAsDataURL
=
(
file
)
=>
{
export
const
readFileAsDataURL
=
(
file
)
=>
{
...
...
spec/frontend/content_editor/extensions/attachment_spec.js
View file @
e28237cf
...
@@ -112,7 +112,7 @@ describe('content_editor/extensions/image', () => {
...
@@ -112,7 +112,7 @@ describe('content_editor/extensions/image', () => {
image
({
image
({
canonicalSrc
:
'
test-file.png
'
,
canonicalSrc
:
'
test-file.png
'
,
src
:
base64EncodedFile
,
src
:
base64EncodedFile
,
alt
:
'
test
file
'
,
alt
:
'
test
-
file
'
,
uploading
:
false
,
uploading
:
false
,
}),
}),
),
),
...
@@ -162,7 +162,7 @@ describe('content_editor/extensions/image', () => {
...
@@ -162,7 +162,7 @@ describe('content_editor/extensions/image', () => {
describe
(
'
when uploading succeeds
'
,
()
=>
{
describe
(
'
when uploading succeeds
'
,
()
=>
{
const
successResponse
=
{
const
successResponse
=
{
link
:
{
link
:
{
markdown
:
'
[test
file](test-file.zip)
'
,
markdown
:
'
[test
-
file](test-file.zip)
'
,
},
},
};
};
...
@@ -171,7 +171,7 @@ describe('content_editor/extensions/image', () => {
...
@@ -171,7 +171,7 @@ describe('content_editor/extensions/image', () => {
});
});
it
(
'
inserts a loading mark
'
,
(
done
)
=>
{
it
(
'
inserts a loading mark
'
,
(
done
)
=>
{
const
expectedDoc
=
doc
(
p
(
loading
({
label
:
'
test
file
'
})));
const
expectedDoc
=
doc
(
p
(
loading
({
label
:
'
test
-
file
'
})));
tiptapEditor
.
on
(
tiptapEditor
.
on
(
'
update
'
,
'
update
'
,
...
@@ -193,7 +193,7 @@ describe('content_editor/extensions/image', () => {
...
@@ -193,7 +193,7 @@ describe('content_editor/extensions/image', () => {
canonicalSrc
:
'
test-file.zip
'
,
canonicalSrc
:
'
test-file.zip
'
,
href
:
`/
${
group
}
/
${
project
}
/-/wikis/test-file.zip`
,
href
:
`/
${
group
}
/
${
project
}
/-/wikis/test-file.zip`
,
},
},
'
test
file
'
,
'
test
-
file
'
,
),
),
),
),
);
);
...
...
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