-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented user media manager #262
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4abe303
Implemented media manager
jaspervriends cb3fa38
Linter
jaspervriends 60906e5
Updated restricted file types
jaspervriends e66e838
Update resources/locale/en.yml
jaspervriends a3ef575
Update resources/locale/en.yml
jaspervriends 8c2d114
Updated feedback
jaspervriends 679f516
Added composer button visibility
jaspervriends e3f46ab
Added user uploads to profile page
jaspervriends File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default function fileToBBcode(file) { | ||
switch (file.tag()) { | ||
// File | ||
case 'file': | ||
return `[upl-file uuid=${file.uuid()} size=${file.humanSize()}]${file.baseName()}[/upl-file]`; | ||
|
||
// Image template | ||
case 'image': | ||
return `[upl-image uuid=${file.uuid()} size=${file.humanSize()} url=${file.url()}]${file.baseName()}[/upl-image]`; | ||
|
||
// Image preview | ||
case 'image-preview': | ||
return `[upl-image-preview url=${file.url()}]`; | ||
|
||
// 'just-url' or unknown | ||
default: | ||
return file.url(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const image = ['image/png', 'image/jpg', 'image/jpeg', 'image/svg+xml']; | ||
const archive = ['application/zip', 'application/x-7z-compressed', 'application/gzip', 'application/vnd.rar', 'application/x-rar-compressed']; | ||
const code = ['text/html', 'text/css', 'text/javascript', 'application/json', 'application/ld+json', 'text/javascript', 'application/x-httpd-php']; | ||
const word = ['application/x-abiword', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']; | ||
|
||
export default function mimeToIcon(fileType) { | ||
// Display image (do not display for) | ||
if (image.indexOf(fileType) >= 0) { | ||
return 'image'; | ||
} | ||
// Display image icon for other types | ||
else if (fileType.includes('image/')) { | ||
return 'far fa-file-image'; | ||
} | ||
// Video icon | ||
else if (fileType.includes('video/')) { | ||
return 'far fa-file-video'; | ||
} | ||
// Archive icon | ||
else if (archive.indexOf(fileType) >= 0) { | ||
return 'far fa-file-archive'; | ||
} | ||
// PDF icon | ||
else if (fileType === 'application/pdf') { | ||
return 'far fa-file-pdf'; | ||
} | ||
// Word | ||
else if (word.indexOf(fileType) >= 0) { | ||
return 'far fa-file-word'; | ||
} | ||
// Audio icon | ||
else if (fileType.includes('audio/')) { | ||
return 'far fa-file-audio'; | ||
} | ||
// Code files | ||
else if (code.indexOf(fileType) >= 0) { | ||
return 'far fa-file-code'; | ||
} | ||
|
||
return 'far fa-file'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Model from 'flarum/Model'; | ||
import mixin from 'flarum/utils/mixin'; | ||
import fileToBBcode from '../fileToBBcode'; | ||
|
||
export default class File extends mixin(Model, { | ||
baseName: Model.attribute('baseName'), | ||
path: Model.attribute('path'), | ||
url: Model.attribute('url'), | ||
type: Model.attribute('type'), | ||
size: Model.attribute('size'), | ||
humanSize: Model.attribute('humanSize'), | ||
createdAt: Model.attribute('createdAt'), | ||
uuid: Model.attribute('uuid'), | ||
tag: Model.attribute('tag'), | ||
}) { | ||
/** | ||
* Use FoF Uploads endpoint | ||
*/ | ||
apiEndpoint() { | ||
return '/fof/uploads' + (this.exists ? '/' + this.data.id : ''); | ||
} | ||
|
||
/** | ||
* Generate bbcode for this file | ||
*/ | ||
bbcode() { | ||
return fileToBBcode(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import app from 'flarum/app'; | ||
import Component from 'flarum/Component'; | ||
import Button from 'flarum/components/Button'; | ||
import FileManagerModal from './FileManagerModal'; | ||
|
||
export default class FileManagerButton extends Component { | ||
view() { | ||
return Button.component({ | ||
className: 'Button fof-upload-button Button--icon', | ||
onclick: this.fileManagerButtonClicked.bind(this), | ||
icon: 'fas fa-photo-video', | ||
title: app.translator.trans('fof-upload.forum.buttons.media'), | ||
}); | ||
} | ||
|
||
/** | ||
* Show tooltip on hover | ||
* | ||
* @param {*} vnode | ||
*/ | ||
oncreate(vnode) { | ||
super.oncreate(vnode); | ||
|
||
// Add tooltip | ||
this.$().tooltip(); | ||
} | ||
|
||
/** | ||
* Event handler for upload button being clicked | ||
* | ||
* @param {PointerEvent} e | ||
*/ | ||
fileManagerButtonClicked(e) { | ||
e.preventDefault(); | ||
|
||
// Open dialog | ||
app.modal.show(FileManagerModal, { | ||
uploader: this.attrs.uploader | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking, but we should probably change this stuff to JSX for better readability in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but as you say, this should be a separate PR to this feature