Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
xquanluu committed Oct 30, 2023
1 parent 4b43fc9 commit d84c64e
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 41 deletions.
5 changes: 2 additions & 3 deletions db/jambones-sql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,8 @@ CREATE TABLE google_custom_voices
google_custom_voice_sid CHAR(36) NOT NULL UNIQUE ,
speech_credential_sid CHAR(36) NOT NULL,
model VARCHAR(512) NOT NULL,
reported_usage TINYINT DEFAULT 0,
language VARCHAR(64) NOT NULL,
voice VARCHAR(64) NOT NULL,
reported_usage ENUM('REPORTED_USAGE_UNSPECIFIED','REALTIME','OFFLINE') DEFAULT 'REALTIME',
name VARCHAR(64) NOT NULL,
PRIMARY KEY (google_custom_voice_sid)
);

Expand Down
18 changes: 6 additions & 12 deletions db/jambones.sqs
Original file line number Diff line number Diff line change
Expand Up @@ -2074,8 +2074,8 @@
<y>1036.00</y>
</location>
<size>
<width>323.00</width>
<height>140.00</height>
<width>521.00</width>
<height>120.00</height>
</size>
<zorder>37</zorder>
<SQLField>
Expand Down Expand Up @@ -2113,19 +2113,13 @@
</SQLField>
<SQLField>
<name><![CDATA[reported_usage]]></name>
<type><![CDATA[TINYINT]]></type>
<defaultValue><![CDATA[0]]></defaultValue>
<type><![CDATA[ENUM('REPORTED_USAGE_UNSPECIFIED','REALTIME','OFFLINE')]]></type>
<defaultValue><![CDATA[REALTIME]]></defaultValue>
<notNull><![CDATA[0]]></notNull>
<uid><![CDATA[A17005D7-81E3-4E12-91EB-6DB23DEAA618]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[language]]></name>
<type><![CDATA[VARCHAR(64)]]></type>
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[C94507FF-477B-41D4-A87F-6DEBBDDED9FF]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[voice]]></name>
<name><![CDATA[name]]></name>
<type><![CDATA[VARCHAR(64)]]></type>
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[D22EED9A-3502-489E-BE0A-5609B76697A8]]></uid>
Expand Down Expand Up @@ -3091,7 +3085,7 @@
<windowHeight><![CDATA[1055.000000]]></windowHeight>
<windowLocationX><![CDATA[1728.000000]]></windowLocationX>
<windowLocationY><![CDATA[37.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{1563, 406}]]></windowScrollOrigin>
<windowScrollOrigin><![CDATA[{1397, 626}]]></windowScrollOrigin>
<windowWidth><![CDATA[1682.000000]]></windowWidth>
</SQLDocumentInfo>
<AllowsIndexRenamingOnInsert><![CDATA[1]]></AllowsIndexRenamingOnInsert>
Expand Down
15 changes: 14 additions & 1 deletion db/upgrade-jambonz-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,20 @@ const sql = {
'ALTER TABLE applications ADD COLUMN fallback_speech_recognizer_language VARCHAR(64)',
'ALTER TABLE applications ADD COLUMN fallback_speech_recognizer_label VARCHAR(64)',
'ALTER TABLE sip_gateways ADD COLUMN pad_crypto BOOLEAN NOT NULL DEFAULT 0',
'ALTER TABLE sip_gateways MODIFY port INTEGER'
'ALTER TABLE sip_gateways MODIFY port INTEGER',
`CREATE TABLE google_custom_voices
(
google_custom_voice_sid CHAR(36) NOT NULL UNIQUE ,
speech_credential_sid CHAR(36) NOT NULL,
model VARCHAR(512) NOT NULL,
reported_usage ENUM('REPORTED_USAGE_UNSPECIFIED','REALTIME','OFFLINE') DEFAULT 'REALTIME',
name VARCHAR(64) NOT NULL,
PRIMARY KEY (google_custom_voice_sid)
)
`,
'CREATE INDEX google_custom_voice_sid_idx ON google_custom_voices (google_custom_voice_sid)',
'CREATE INDEX speech_credential_sid_idx ON google_custom_voices (speech_credential_sid)',
'ALTER TABLE google_custom_voices ADD FOREIGN KEY speech_credential_sid_idxfk (speech_credential_sid) REFERENCES speech_credentials (speech_credential_sid) ON DELETE CASCADE'
]
};

Expand Down
22 changes: 17 additions & 5 deletions lib/models/google-custom-voice.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ class GoogleCustomVoice extends Model {
const [rows] = await promisePool.query(sql, speech_credential_sid);
return rows;
}

static async retrieveAllByLabel(service_provider_sid, account_sid, label) {
let sql;
if (account_sid) {
sql = `SELECT gcv.* FROM ${this.table} gcv
LEFT JOIN speech_credentials sc ON gcv.speech_credential_sid = sc.speech_credential_sid
WHERE sc.account_sid = ? OR (sc.account_sid is NULL && sc.service_provider_sid = ?) ${label ? 'AND label = ?' : ''}`;
} else {
sql = `SELECT gcv.* FROM ${this.table} gcv
LEFT JOIN speech_credentials sc ON gcv.speech_credential_sid = sc.speech_credential_sid
WHERE sc.service_provider_sid = ? ${label ? 'AND label = ?' : ''}`;
}
const [rows] = await promisePool.query(sql, [...(account_sid ?
[account_sid, service_provider_sid] : [service_provider_sid]), label]);
return rows;
}
}
GoogleCustomVoice.table = 'google_custom_voices';
GoogleCustomVoice.fields = [
Expand All @@ -35,13 +51,9 @@ GoogleCustomVoice.fields = [
type: 'number'
},
{
name: 'language',
name: 'name',
type: 'string',
required: true
},
{
name: 'voice',
type: 'string'
}
];

Expand Down
26 changes: 22 additions & 4 deletions lib/routes/api/google-custom-voices.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,30 @@ decorate(router, GoogleCustomVoice, ['add', 'retrieve', 'update', 'delete'], pre

router.get('/', async(req, res) => {
const logger = req.app.locals.logger;
const account_sid = req.user.account_sid || req.query.account_sid;
const service_provider_sid = req.user.service_provider_sid || req.query.service_provider_sid;
const speech_credential_sid = req.query.speech_credential_sid;
if (!speech_credential_sid) {
throw new DbErrorBadRequest('Missing query parameter speech_credential_sid');
}
const label = req.query.label;
try {
const results = await GoogleCustomVoice.retrieveAllBySpeechCredentialSid(speech_credential_sid);
let results = [];
if (speech_credential_sid) {
const [cred] = await SpeechCredential.retrieve(speech_credential_sid);
if (!cred) {
return res.sendStatus(404);
}
if (account_sid && cred.account_sid && cred.account_sid !== account_sid) {
throw new DbErrorForbidden('Insufficient privileges');
}
if (service_provider_sid && cred.service_provider_sid && cred.service_provider_sid !== service_provider_sid) {
throw new DbErrorForbidden('Insufficient privileges');
}
results = await GoogleCustomVoice.retrieveAllBySpeechCredentialSid(speech_credential_sid);
} else {
if (!account_sid && !service_provider_sid) {
throw new DbErrorBadRequest('missing account_sid or service_provider_sid in query parameters');
}
results = await GoogleCustomVoice.retrieveAllByLabel(service_provider_sid, account_sid, label);
}
res.status(200).json(results);
} catch (err) {
sysError(logger, res, err);
Expand Down
189 changes: 189 additions & 0 deletions lib/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ tags:
description: Least Cost Routing Routes operations
- name: LcrCarrierSetEntries
description: Least Cost Routing Carrier Set Entries operation
- name: GoogleCustomVOices
description: Google Custom voices operation
paths:
/BetaInviteCodes:
post:
Expand Down Expand Up @@ -4625,6 +4627,173 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
/GoogleCustomVoices:
post:
tags:
- GoogleCustomVoices
summary: create a Google custom voice
operationId: createGoogleCustomVoice
requestBody:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/GoogleCustomVoice'
required:
- speech_credential_sid
- name
- reported_usage
- model
responses:
201:
description: Least Cost Routing Carrier Set Entry successfully created
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessfulAdd'
400:
description: bad request
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
422:
description: unprocessable entity
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
get:
tags:
- GoogleCustomVoices
parameters:
- in: query
name: service_provider_sid
required: false
schema:
type: string
description: return only the google voice custom operated belong to this service provider
- in: query
name: account_sid
required: false
schema:
type: string
description: return only the google voice custom operated belong to this account_sid

- in: query
name: speech_credential_sid
required: false
schema:
type: string
description: return only the google voice custom operated belong to this speech credential
summary: list google custom voices
operationId: listGoogleCustomVoices
responses:
200:
description: list oflist google custom voices
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/GoogleCustomVoice'
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
/GoogleCustomVoices/{GoogleCustomVoiceSid}:
parameters:
- name: GoogleCustomVoiceSid
in: path
required: true
style: simple
explode: false
schema:
type: string
delete:
tags:
- GoogleCustomVoices
summary: delete a google custom voice
operationId: deleteGoogleCustomVoice
responses:
204:
description: google custom voice successfully deleted
404:
description: google custom voice not found
422:
description: unprocessable entity
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
msg: a service provider with active accounts can not be deleted
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
get:
tags:
- GoogleCustomVoices
summary: retrieve google custom voice
operationId: getGoogleCustomVoice
responses:
200:
description: google custom voice found
content:
application/json:
schema:
$ref: '#/components/schemas/GoogleCustomVoice'
404:
description: google custom voice not found
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
put:
tags:
- GoogleCustomVoices
summary: update google custom voice
operationId: updateGoogleCustomVoice
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GoogleCustomVoice'
responses:
204:
description: google custom voice updated
content:
application/json:
schema:
$ref: '#/components/schemas/GoogleCustomVoice'
400:
description: bad request
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
404:
description: least cost routing carrier set entry not found
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
components:
securitySchemes:
bearerAuth:
Expand Down Expand Up @@ -5583,6 +5752,26 @@ components:
- lcr_route_sid
- voip_carrier_sid
- priority
GoogleCustomVoice:
type: object
properties:
speech_credential_sid:
type: string
example: 3fa85f64-5717-4562-b3fc-2c963f66afa6
name:
type: string
example: Sally
reported_usage:
type: string
example: REALTIME
model:
type: string
example: projects/12412312/locations/global/models/2134124123-2dbf-43be-9593-12314123
required:
- speech_credential_sid
- name
- reported_usage
- model

security:
- bearerAuth: []
Loading

0 comments on commit d84c64e

Please sign in to comment.