mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 18:45:57 +00:00
fix: build url
This commit is contained in:
parent
c174d9d145
commit
9c44bafb8a
@ -13,6 +13,7 @@ import { THydratedDocument } from 'mongoose';
|
|||||||
import { FileType } from '@/chat/schemas/types/attachment';
|
import { FileType } from '@/chat/schemas/types/attachment';
|
||||||
import { config } from '@/config';
|
import { config } from '@/config';
|
||||||
import { BaseSchema } from '@/utils/generics/base-schema';
|
import { BaseSchema } from '@/utils/generics/base-schema';
|
||||||
|
import { buildURL } from '@/utils/helpers/URL';
|
||||||
|
|
||||||
import { MIME_REGEX } from '../utilities';
|
import { MIME_REGEX } from '../utilities';
|
||||||
|
|
||||||
@ -89,7 +90,10 @@ export class Attachment extends BaseSchema {
|
|||||||
attachmentId: string,
|
attachmentId: string,
|
||||||
attachmentName: string = '',
|
attachmentName: string = '',
|
||||||
): string {
|
): string {
|
||||||
return `${config.parameters.apiUrl}/attachment/download/${attachmentId}/${attachmentName}`;
|
return buildURL(
|
||||||
|
config.parameters.apiUrl,
|
||||||
|
`/attachment/download/${attachmentId}/${attachmentName}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,7 +123,10 @@ export const AttachmentModel: ModelDefinition = {
|
|||||||
|
|
||||||
AttachmentModel.schema.virtual('url').get(function () {
|
AttachmentModel.schema.virtual('url').get(function () {
|
||||||
if (this._id && this.name)
|
if (this._id && this.name)
|
||||||
return `${config.apiPath}/attachment/download/${this._id}/${this.name}`;
|
return buildURL(
|
||||||
|
config.apiPath,
|
||||||
|
`/attachment/download/${this._id}/${this.name}`,
|
||||||
|
);
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
|
@ -16,7 +16,7 @@ export const config: Config = {
|
|||||||
translationFilename: process.env.I18N_TRANSLATION_FILENAME || 'messages',
|
translationFilename: process.env.I18N_TRANSLATION_FILENAME || 'messages',
|
||||||
},
|
},
|
||||||
appPath: process.cwd(),
|
appPath: process.cwd(),
|
||||||
apiPath: process.env.API_ORIGIN,
|
apiPath: process.env.API_ORIGIN || 'http://localhost:4000',
|
||||||
frontendPath: process.env.FRONTEND_ORIGIN
|
frontendPath: process.env.FRONTEND_ORIGIN
|
||||||
? process.env.FRONTEND_ORIGIN.split(',')[0]
|
? process.env.FRONTEND_ORIGIN.split(',')[0]
|
||||||
: 'http://localhost:8080',
|
: 'http://localhost:8080',
|
||||||
|
@ -18,6 +18,7 @@ import { NlpSampleFull } from '@/nlp/schemas/nlp-sample.schema';
|
|||||||
import { NlpEntityService } from '@/nlp/services/nlp-entity.service';
|
import { NlpEntityService } from '@/nlp/services/nlp-entity.service';
|
||||||
import { NlpSampleService } from '@/nlp/services/nlp-sample.service';
|
import { NlpSampleService } from '@/nlp/services/nlp-sample.service';
|
||||||
import { NlpService } from '@/nlp/services/nlp.service';
|
import { NlpService } from '@/nlp/services/nlp.service';
|
||||||
|
import { buildURL } from '@/utils/helpers/URL';
|
||||||
|
|
||||||
import { DatasetType, NlpParseResultType } from './types';
|
import { DatasetType, NlpParseResultType } from './types';
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ export default class DefaultNlpHelper extends BaseNlpHelper {
|
|||||||
const nluData: DatasetType = await self.format(samples, entities);
|
const nluData: DatasetType = await self.format(samples, entities);
|
||||||
// Train samples
|
// Train samples
|
||||||
const result = await this.httpService.axiosRef.post(
|
const result = await this.httpService.axiosRef.post(
|
||||||
`${this.settings.endpoint}/train`,
|
buildURL(this.settings.endpoint, `/train`),
|
||||||
nluData,
|
nluData,
|
||||||
{
|
{
|
||||||
params: {
|
params: {
|
||||||
@ -111,7 +112,7 @@ export default class DefaultNlpHelper extends BaseNlpHelper {
|
|||||||
const nluTestData: DatasetType = await self.format(samples, entities);
|
const nluTestData: DatasetType = await self.format(samples, entities);
|
||||||
// Evaluate model with test samples
|
// Evaluate model with test samples
|
||||||
return await this.httpService.axiosRef.post(
|
return await this.httpService.axiosRef.post(
|
||||||
`${this.settings.endpoint}/evaluate`,
|
buildURL(this.settings.endpoint, `/evaluate`),
|
||||||
nluTestData,
|
nluTestData,
|
||||||
{
|
{
|
||||||
params: {
|
params: {
|
||||||
@ -190,7 +191,7 @@ export default class DefaultNlpHelper extends BaseNlpHelper {
|
|||||||
try {
|
try {
|
||||||
const { data: nlp } =
|
const { data: nlp } =
|
||||||
await this.httpService.axiosRef.post<NlpParseResultType>(
|
await this.httpService.axiosRef.post<NlpParseResultType>(
|
||||||
`${this.settings.endpoint}/parse`,
|
buildURL(this.settings.endpoint, '/parse'),
|
||||||
{
|
{
|
||||||
q: text,
|
q: text,
|
||||||
project,
|
project,
|
||||||
|
9
api/src/utils/helpers/URL.ts
Normal file
9
api/src/utils/helpers/URL.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export const buildURL = (baseUrl: string, relativePath: string): string => {
|
||||||
|
try {
|
||||||
|
const url = new URL(relativePath, baseUrl);
|
||||||
|
|
||||||
|
return url.toString();
|
||||||
|
} catch {
|
||||||
|
throw new Error(`Invalid base URL: ${baseUrl}`);
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user