mirror of
https://github.com/HeyPuter/puter.git
synced 2026-02-19 21:21:23 -06:00
dev: add default parameters for driver interfaces
This commit is contained in:
@@ -11,6 +11,7 @@ class IPGeoService extends BaseService {
|
||||
methods: {
|
||||
ipgeo: {
|
||||
description: 'Report geolocation information',
|
||||
default_parameter: 'ip',
|
||||
parameters: {
|
||||
ip: {
|
||||
type: 'string',
|
||||
|
||||
@@ -11,6 +11,7 @@ class NewsDataService extends BaseService {
|
||||
methods: {
|
||||
newsdata: {
|
||||
description: 'Report geolocation information',
|
||||
default_parameter: 'q',
|
||||
parameters: {
|
||||
'*': {
|
||||
type: 'json',
|
||||
|
||||
@@ -25,6 +25,7 @@ const BaseService = require("../BaseService");
|
||||
const { PermissionUtil } = require("../auth/PermissionService");
|
||||
const { Invoker } = require("../../../../putility/src/libs/invoker");
|
||||
const { get_user } = require("../../helpers");
|
||||
const { whatis } = require('../../util/langutil');
|
||||
|
||||
const strutil = require('@heyputer/putility').libs.string;
|
||||
|
||||
@@ -515,6 +516,11 @@ class DriverService extends BaseService {
|
||||
if ( ! method ) {
|
||||
throw svc_apiError.create('method_not_found', { interface_name, method_name });
|
||||
}
|
||||
|
||||
if ( method.hasOwnProperty('default_parameter') && whatis(args) !== 'object' ) {
|
||||
args = { [method.default_parameter]: args };
|
||||
}
|
||||
|
||||
|
||||
for ( const [arg_name, arg_descriptor] of Object.entries(method.parameters) ) {
|
||||
const arg_value = arg_name === '*' ? args : args[arg_name];
|
||||
|
||||
Reference in New Issue
Block a user