-
Notifications
You must be signed in to change notification settings - Fork 4
/
plugin.rb
59 lines (50 loc) · 1.4 KB
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# name: lrqdo-editor
# about: La ruche qui dit oui - editor
# version: 1.0.3
# authors: Sébastien Bourdu
# url: https://github.com/ekkans/lrqdo-editor-plugin-discourse
enabled_site_setting :lrqdo_editor_enabled
register_asset 'stylesheets/editor.css'
after_initialize do
require_dependency 'uploads_controller'
class ::UploadsController
def editor
me = current_user
type = 'composer'
file = params[:file] || params[:files].try(:first)
url = nil
for_private_message = true
pasted = false
is_api = true
retain_hours = 876000
info = ::UploadsController.create_upload(
current_user: me,
file: file,
url: url,
type: type,
for_private_message: for_private_message,
pasted: pasted,
is_api: is_api,
retain_hours: retain_hours
)
render json: {
files: [ ::UploadsController.serialize_upload(info) ]
}
end
end
require_dependency 'application_controller'
class ::EmojisController < ::ApplicationController
def search
term = params[:term] || ''
max_results = 5
matches = Emoji.standard.select do |emoji|
emoji.name.start_with? term
end[0, max_results]
render json: matches
end
end
Discourse::Application.routes.append do
post "uploads-editor" => "uploads#editor"
get "emojis/search" => "emojis#search"
end
end