-
Notifications
You must be signed in to change notification settings - Fork 42
[4 / 7] - Item Restoration #201
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
base: master
Are you sure you want to change the base?
Changes from all commits
d56d53d
ba1c597
167a8cf
6f4f17b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,23 +11,31 @@ public static function ItemRestoreList($request) { | |
| } | ||
|
|
||
| public static function ItemRestore($data) { | ||
| $item = $data['item']; | ||
| $cname = $data['cname']; | ||
| $item = filter_var($data['item'] ?? null, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]); | ||
| if ($item === false) { | ||
| return new \WP_Error('invalid_item', 'Invalid item id.', ['status' => 400]); | ||
| } | ||
| if (!ACoreServices::I()->currentAccountOwnsCharacterName($cname)) { | ||
| return new \WP_Error('forbidden', 'You do not own that character.', ['status' => 403]); | ||
| } | ||
| return ACoreServices::I()->getServerSoap()->executeCommand("item restore $item $cname"); | ||
|
TheSCREWEDSoftware marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| add_action( 'rest_api_init', function () { | ||
| register_rest_route( ACORE_SLUG . '/v1', 'item-restore/list/(?P<cguid>\d+)', array( | ||
| 'methods' => 'GET', | ||
| 'callback' => function( $request ) { | ||
| 'methods' => 'GET', | ||
| 'permission_callback' => function() { return is_user_logged_in(); }, | ||
| 'callback' => function( $request ) { | ||
| return ToolsApi::ItemRestoreList($request); | ||
|
Comment on lines
+30
to
31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Convert denied list requests into REST errors.
Proposed REST error handling 'permission_callback' => function() { return is_user_logged_in(); },
'callback' => function( $request ) {
- return ToolsApi::ItemRestoreList($request);
+ try {
+ return ToolsApi::ItemRestoreList($request);
+ } catch (\InvalidArgumentException $e) {
+ return new \WP_Error('invalid_character', 'Character not found.', ['status' => 404]);
+ }
}🤖 Prompt for AI Agents |
||
| } | ||
| )); | ||
|
|
||
| register_rest_route( ACORE_SLUG . '/v1', 'item-restore', array( | ||
| 'methods' => 'POST', | ||
| 'callback' => function( $request ) { | ||
| 'methods' => 'POST', | ||
| 'permission_callback' => function() { return is_user_logged_in(); }, | ||
| 'callback' => function( $request ) { | ||
|
|
||
| // if free item-restoration is disabled, return | ||
| if (Opts::I()->acore_item_restoration != '1') { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.