diff --git a/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template b/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template index 78fb27c33d..1e1cc4564a 100644 --- a/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template +++ b/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template @@ -7,12 +7,18 @@ export class <%= name %>Service { apiName = '<%= apiName %>';<% for (let {body, signature} of methods) { %> + <% + const isBlob = body.isBlobMethod() ; + const responseType = isBlob ? "Blob":body.responseType; + %> <%= camel(signature.name) %> = (<%= serializeParameters(signature.parameters) %>) => - this.restService.request<<%= body.requestType %>, <%= body.responseType %>>({ - method: '<%= body.method %>',<% + this.restService.request<<%= body.requestType %>, <%= responseType %>>({ + method: '<%= body.method %>',<% if (body.responseType === 'string') { %> - responseType: 'text',<% } %> + responseType: 'text',<% } %><% + if (isBlob) { %> + responseType: 'blob',<% } %> url: <%= body.url %>,<% if (body.params.length) { %> params: { <%= body.params.join(', ') %> },<% } diff --git a/npm/ng-packs/packages/schematics/src/constants/volo.ts b/npm/ng-packs/packages/schematics/src/constants/volo.ts index 00fde72c79..d45a4b9e72 100644 --- a/npm/ng-packs/packages/schematics/src/constants/volo.ts +++ b/npm/ng-packs/packages/schematics/src/constants/volo.ts @@ -1 +1,2 @@ export const VOLO_REGEX = /^Volo\.Abp\.(Application\.Dtos|ObjectExtending)/; +export const VOLO_REMOTE_STREAM_CONTENT = 'Volo.Abp.Content.IRemoteStreamContent' diff --git a/npm/ng-packs/packages/schematics/src/models/method.ts b/npm/ng-packs/packages/schematics/src/models/method.ts index d8f56e383e..d54d4303b9 100644 --- a/npm/ng-packs/packages/schematics/src/models/method.ts +++ b/npm/ng-packs/packages/schematics/src/models/method.ts @@ -4,6 +4,7 @@ import { getParamName } from '../utils/methods'; import { ParameterInBody } from './api-definition'; import { Property } from './model'; import { Omissible } from './util'; +import {VOLO_REMOTE_STREAM_CONTENT} from "../constants"; // eslint-disable-next-line @typescript-eslint/no-var-requires const shouldQuote = require('should-quote'); @@ -39,6 +40,7 @@ export class Body { body?: string; method: string; params: string[] = []; + responseTypeWithNamespace: string; requestType = 'any'; responseType: string; url: string; @@ -77,6 +79,10 @@ export class Body { this.setUrlQuotes(); } + isBlobMethod(){ + return this.responseTypeWithNamespace === VOLO_REMOTE_STREAM_CONTENT + } + private setUrlQuotes() { this.url = /{/.test(this.url) ? `\`/${this.url}\`` : `'/${this.url}'`; } @@ -84,5 +90,5 @@ export class Body { export type BodyOptions = Omissible< Omit, - 'params' | 'requestType' + 'params' | 'requestType' | 'isBlobMethod' >; diff --git a/npm/ng-packs/packages/schematics/src/utils/service.ts b/npm/ng-packs/packages/schematics/src/utils/service.ts index 4e2fdc7c02..28ce82e3f7 100644 --- a/npm/ng-packs/packages/schematics/src/utils/service.ts +++ b/npm/ng-packs/packages/schematics/src/utils/service.ts @@ -22,6 +22,7 @@ import { } from './type'; import { eBindingSourceId } from '../enums'; import { camelizeHyphen } from './text'; +import {VOLO_REMOTE_STREAM_CONTENT} from "../constants"; export function serializeParameters(parameters: Property[]) { return parameters.map(p => p.name + p.optional + ': ' + p.type + p.default, '').join(', '); @@ -38,7 +39,8 @@ export function createControllerToServiceMapper({ const name = controller.controllerName; const namespace = parseNamespace(solution, controller.type); const actions = Object.values(controller.actions); - const imports = actions.reduce(createActionToImportsReducer(solution, types, namespace), []); + const typeWithoutIRemoteStreamContent = getTypesWithoutIRemoteStreamContent(types) + const imports = actions.reduce(createActionToImportsReducer(solution, typeWithoutIRemoteStreamContent, namespace), []); imports.push(new Import({ path: '@abp/ng.core', specifiers: ['RestService'] })); imports.push(new Import({ path: '@angular/core', specifiers: ['Injectable'] })); sortImports(imports); @@ -48,6 +50,11 @@ export function createControllerToServiceMapper({ }; } +function getTypesWithoutIRemoteStreamContent(types: Record) { + const newType = {...types} + delete newType[VOLO_REMOTE_STREAM_CONTENT] + return newType +} function sortMethods(methods: Method[]) { methods.sort((a, b) => (a.signature.name > b.signature.name ? 1 : -1)); } @@ -68,7 +75,8 @@ export function createActionToBodyMapper() { return ({ httpMethod, parameters, returnValue, url }: Action) => { const responseType = adaptType(returnValue.typeSimple); - const body = new Body({ method: httpMethod, responseType, url }); + const responseTypeWithNamespace = returnValue.typeSimple; + const body = new Body({ method: httpMethod, responseType, url ,responseTypeWithNamespace}); parameters.forEach(body.registerActionParameter);