Skip to content

Commit fc2ce11

Browse files
committed
Add template, add files when new service is added.
1 parent 5600f32 commit fc2ce11

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

app/Repositories/ServiceRepository/Service.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function create(array $data)
4747
$validator = Validator::make($data, [
4848
'name' => 'required|string|min:1|max:255',
4949
'description' => 'required|string',
50-
'file' => 'required|regex:/^[\w.-]{1,50}$/',
50+
'file' => 'required|unique:services,file|regex:/^[\w.-]{1,50}$/',
5151
'executable' => 'max:255|regex:/^(.*)$/',
5252
'startup' => 'string'
5353
]);
@@ -56,15 +56,23 @@ public function create(array $data)
5656
throw new DisplayValidationException($validator->errors());
5757
}
5858

59-
if (Models\Service::where('file', $data['file'])->first()) {
60-
throw new DisplayException('A service using that configuration file already exists on the system.');
61-
}
62-
6359
$data['author'] = env('SERVICE_AUTHOR', (string) Uuid::generate(4));
6460

6561
$service = new Models\Service;
66-
$service->fill($data);
67-
$service->save();
62+
DB::beginTransaction();
63+
64+
try {
65+
$service->fill($data);
66+
$service->save();
67+
68+
Storage::put('services/' . $data['file'] . '/main.json', '{}');
69+
Storage::copy('services/.templates/index.js', 'services/' . $data['file'] . '/index.js');
70+
71+
DB::commit();
72+
} catch (\Exception $ex) {
73+
DB::rollBack();
74+
throw $ex;
75+
}
6876

6977
return $service->id;
7078
}
@@ -101,11 +109,11 @@ public function delete($id)
101109

102110
DB::beginTransaction();
103111
try {
104-
Storage::deleteDirectory('services/' . $service->file);
105-
106112
Models\ServiceVariables::whereIn('option_id', $options->get()->toArray())->delete();
107113
$options->delete();
108114
$service->delete();
115+
116+
Storage::deleteDirectory('services/' . $service->file);
109117
DB::commit();
110118
} catch (\Exception $ex) {
111119
DB::rollBack();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
/**
4+
* Pterodactyl - Daemon
5+
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
const rfr = require('rfr');
26+
27+
const Core = rfr('src/services/index.js');
28+
29+
class Service extends Core {}
30+
31+
module.exports = Service;

0 commit comments

Comments
 (0)