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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# frozen_string_literal: true
module API
module VsCode
module Settings
class VsCodeSettingsSync < ::API::Base
include ::VsCode::Settings
feature_category :web_ide
before do
authenticate!
header 'Access-Control-Expose-Headers', 'etag'
end
resource :vscode do
resource :settings_sync do
content_type :json, 'application/json'
content_type :json, 'text/plain'
desc 'Get the settings manifest for Settings Sync' do
success [Entities::VsCodeManifest]
tags %w[vscode]
end
get '/v1/manifest' do
settings = SettingsFinder.new(current_user, SETTINGS_TYPES).execute
presenter = VsCodeManifestPresenter.new(settings)
present presenter, with: Entities::VsCodeManifest
end
desc 'Get a specific setting resource' do
success [Entities::VsCodeSetting]
tags %w[vscode]
end
params do
requires :resource_name, type: String, desc: 'Name of the resource such as settings'
requires :id, type: String, desc: 'ID of the resource to retrieve'
end
get '/v1/resource/:resource_name/:id' do
authenticate!
setting_name = params[:resource_name]
setting = nil
if params[:resource_name] == 'machines'
setting = DEFAULT_MACHINE
else
settings = SettingsFinder.new(current_user, [setting_name]).execute
setting = settings.first if settings.present?
end
if setting.nil?
status :no_content
header :etag, NO_CONTENT_ETAG
body false
else
header :etag, setting[:uuid]
presenter = VsCodeSettingPresenter.new setting
present presenter, with: Entities::VsCodeSetting
end
end
desc 'Update a specific setting'
params do
requires :resource_name, type: String, desc: 'Name of the resource such as settings'
end
post '/v1/resource/:resource_name' do
authenticate!
response = CreateOrUpdateService.new(current_user: current_user, params: {
content: params[:content],
version: params[:version],
setting_type: params[:resource_name]
}).execute
if response.success?
header 'Access-Control-Expose-Headers', 'etag'
header 'Etag', response.payload[:uuid]
present "OK"
else
error!(response.message, 400)
end
end
end
end
end
end
end
end
|