Commit b2a5f4da authored by ml's avatar ml

资产管理后台-oss 修改

parent be44fd95
...@@ -298,7 +298,7 @@ async function updateImageUrl(dbRealNameInfo: any) { ...@@ -298,7 +298,7 @@ async function updateImageUrl(dbRealNameInfo: any) {
let identityFrondSide = dbRealNameInfo.identity_frond_side; let identityFrondSide = dbRealNameInfo.identity_frond_side;
if (identityFrondSide) { if (identityFrondSide) {
if (!identityFrondSide.includes("http")) { if (!identityFrondSide.includes("http")) {
dbRealNameInfo.identity_frond_side_small = await ossUtils.resizeWithWaterMark(identityFrondSide, "KTX", 300); dbRealNameInfo.identity_frond_side_small = await ossUtils.resizeWithWaterMark(identityFrondSide, "KTX", 200);
dbRealNameInfo.identity_frond_side = await ossUtils.withWaterMark(identityFrondSide, "KTX"); dbRealNameInfo.identity_frond_side = await ossUtils.withWaterMark(identityFrondSide, "KTX");
} }
else { else {
...@@ -313,7 +313,7 @@ async function updateImageUrl(dbRealNameInfo: any) { ...@@ -313,7 +313,7 @@ async function updateImageUrl(dbRealNameInfo: any) {
let identityOtherSide = dbRealNameInfo.identity_other_side; let identityOtherSide = dbRealNameInfo.identity_other_side;
if (identityOtherSide) { if (identityOtherSide) {
if (!identityOtherSide.includes("http")) { if (!identityOtherSide.includes("http")) {
dbRealNameInfo.identity_other_side_small = await ossUtils.resizeWithWaterMark(identityOtherSide, "KTX", 300); dbRealNameInfo.identity_other_side_small = await ossUtils.resizeWithWaterMark(identityOtherSide, "KTX", 200);
dbRealNameInfo.identity_other_side = await ossUtils.withWaterMark(identityOtherSide, "KTX"); dbRealNameInfo.identity_other_side = await ossUtils.withWaterMark(identityOtherSide, "KTX");
} }
else { else {
...@@ -329,7 +329,7 @@ async function updateImageUrl(dbRealNameInfo: any) { ...@@ -329,7 +329,7 @@ async function updateImageUrl(dbRealNameInfo: any) {
let identityInHand = dbRealNameInfo.identity_in_hand; let identityInHand = dbRealNameInfo.identity_in_hand;
if (identityInHand) { if (identityInHand) {
if (!identityInHand.includes("http")) { if (!identityInHand.includes("http")) {
dbRealNameInfo.identity_in_hand_small = await ossUtils.resizeWithWaterMark(identityInHand, "KTX", 300); dbRealNameInfo.identity_in_hand_small = await ossUtils.resizeWithWaterMark(identityInHand, "KTX", 200);
dbRealNameInfo.identity_in_hand = await ossUtils.withWaterMark(identityInHand, "KTX"); dbRealNameInfo.identity_in_hand = await ossUtils.withWaterMark(identityInHand, "KTX");
} }
else { else {
...@@ -345,7 +345,7 @@ async function updateImageUrl(dbRealNameInfo: any) { ...@@ -345,7 +345,7 @@ async function updateImageUrl(dbRealNameInfo: any) {
let latestPhoto = dbRealNameInfo.latest_photo; let latestPhoto = dbRealNameInfo.latest_photo;
if (latestPhoto) { if (latestPhoto) {
if (!latestPhoto.includes("http")) { if (!latestPhoto.includes("http")) {
dbRealNameInfo.latest_photo_small = await ossUtils.resizeWithWaterMark(latestPhoto, "KTX", 300); dbRealNameInfo.latest_photo_small = await ossUtils.resizeWithWaterMark(latestPhoto, "KTX", 200);
dbRealNameInfo.latest_photo = await ossUtils.withWaterMark(latestPhoto, "KTX"); dbRealNameInfo.latest_photo = await ossUtils.withWaterMark(latestPhoto, "KTX");
} }
else { else {
......
...@@ -2,38 +2,20 @@ let { ossUtils } = require('@madex/ex-js-common'); ...@@ -2,38 +2,20 @@ let { ossUtils } = require('@madex/ex-js-common');
let { logger } = require('@madex/ex-js-public'); let { logger } = require('@madex/ex-js-public');
const sizeOf = require('image-size'); const sizeOf = require('image-size');
const axios = require("axios"); const axios = require("axios");
/**
* 获取访问链接
* @param url
*/
export const getKycImageUrl = async function (url: string) {
return await getSignatureUrl(url)
}
/** /**
* 获取签名后的图片链接 *
* @param url * @param url
* @param style * @param text
* @param font_size
*/ */
async function getSignatureUrl(url: string, style?: string | any) {
let res: string | any;
let newUrl = url.replace(/^\/+/, '');
if (style) {
res = await ossUtils.getUrlResize(newUrl, style);
}
else {
res = await ossUtils.getUrl(newUrl);
}
return res;
}
export const resizeWithWaterMark = async function (url: string, text: string, font_size?: number) { export const resizeWithWaterMark = async function (url: string, text: string, font_size?: number) {
let style = await watermarkStyle(text, font_size ? font_size : 60) let waterUrl = await getWatermarkUrl(url, text, font_size ? font_size : 60)
return await getSignatureUrl(url, style); return waterUrl;
} }
export const getImageWidth = async function (urlStr: string) { let getImageWidth = async function (urlStr: string) {
try { try {
let response = await axios({ let response = await axios({
url: urlStr, url: urlStr,
...@@ -51,7 +33,7 @@ export const getImageWidth = async function (urlStr: string) { ...@@ -51,7 +33,7 @@ export const getImageWidth = async function (urlStr: string) {
} }
export const withWaterMark = async function (url: string, text: string) { export const withWaterMark = async function (url: string, text: string) {
let imgUrl = await getKycImageUrl(url); let imgUrl = await ossUtils.getUrl(url);
let imageWidth = await getImageWidth(imgUrl); let imageWidth = await getImageWidth(imgUrl);
if (imageWidth <= 0) { if (imageWidth <= 0) {
imageWidth = 1000; imageWidth = 1000;
...@@ -60,15 +42,20 @@ export const withWaterMark = async function (url: string, text: string) { ...@@ -60,15 +42,20 @@ export const withWaterMark = async function (url: string, text: string) {
if (fontSize > 999) { if (fontSize > 999) {
fontSize = 999; fontSize = 999;
} }
let style = await watermarkStyle(text, fontSize); let waterUrl = await getWatermarkUrl(url, text, fontSize);
return await getSignatureUrl(url, style); return waterUrl;
} }
/**
export const watermarkStyle = async function (text: string, font_size?: number) { * 获取带水印的图片地址
* @param url url
* @param text 水印文案
* @param size 水印大小
*/
let getWatermarkUrl = async function (url: string, text: string, size?: number) {
let base64 = Buffer.from(text).toString('base64'); let base64 = Buffer.from(text).toString('base64');
let textWatermark = base64.replace("+", "-").replace('/', '_').replace("=", ""); let textWatermark = base64.replace("+", "-").replace('/', '_').replace("=", "");
return "/watermark,text_" + textWatermark + ",g_center,x_10,y_10,t_10,fill_1,color_FFFFFF,size_" + font_size ? font_size : ""; return ossUtils.getUrlWatermark(url, textWatermark, size);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment