mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
feat(plantuml): support svg
This commit is contained in:
@@ -185,10 +185,11 @@ const searchFile = async (ctx: any, next: any) => {
|
||||
}
|
||||
|
||||
const plantumlGen = async (ctx: any, next: any) => {
|
||||
if (ctx.path.startsWith('/api/plantuml/png')) {
|
||||
ctx.type = 'image/png'
|
||||
if (ctx.path.startsWith('/api/plantuml')) {
|
||||
try {
|
||||
ctx.body = await plantuml(ctx.query.data)
|
||||
const { type, content } = await plantuml(ctx.query.data)
|
||||
ctx.type = type
|
||||
ctx.body = content
|
||||
ctx.set('cache-control', 'max-age=86400') // 1 day.
|
||||
} catch (error) {
|
||||
ctx.body = error
|
||||
|
||||
@@ -15,7 +15,7 @@ function plantumlBase64 (base64: string) {
|
||||
return base64.split('').map(x => map[x] || '').join('')
|
||||
}
|
||||
|
||||
export default async function (data: string) {
|
||||
export default async function (data: string): Promise<{ content: any, type: string }> {
|
||||
const code = pako.inflateRaw(Buffer.from(data, 'base64'))
|
||||
|
||||
const api = config.get('plantuml-api', 'local')
|
||||
@@ -37,14 +37,14 @@ export default async function (data: string) {
|
||||
puml.in.write(code)
|
||||
puml.in.end()
|
||||
|
||||
return puml.out
|
||||
return { content: puml.out, type: 'image/png' }
|
||||
} else {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
request({ url: api.replace('{data}', plantumlBase64(data)), encoding: null }, function (err: any, res: any) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(res.body)
|
||||
resolve({ content: res.body, type: res.headers['content-type'] })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@ import { DOM_ATTR_NAME } from '@fe/support/args'
|
||||
|
||||
const emptySrc = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
|
||||
|
||||
const baseUrl = location.origin + '/api/plantuml/png'
|
||||
const baseUrl = location.origin + '/api/plantuml'
|
||||
|
||||
const MarkdownItPlugin = function umlPlugin (md: Markdown, options: any) {
|
||||
function generateSourceDefault (umlCode: string) {
|
||||
|
||||
@@ -123,9 +123,17 @@ const schema: Schema = {
|
||||
defaultValue: 'local',
|
||||
title: 'T_setting-panel.schema.plantuml-api',
|
||||
type: 'string',
|
||||
enum: ['local', 'https://www.plantuml.com/plantuml/png/{data}'],
|
||||
enum: [
|
||||
'local',
|
||||
'https://www.plantuml.com/plantuml/png/{data}',
|
||||
'https://www.plantuml.com/plantuml/svg/{data}',
|
||||
],
|
||||
options: {
|
||||
enum_titles: ['Local - Need Java and Graphviz', 'Online (plantuml.com)'],
|
||||
enum_titles: [
|
||||
'Local - Need Java and Graphviz',
|
||||
'Online (plantuml.com) - PNG',
|
||||
'Online (plantuml.com) - SVG',
|
||||
],
|
||||
},
|
||||
required: true,
|
||||
group: 'other',
|
||||
|
||||
Reference in New Issue
Block a user