@@ -8,6 +8,7 @@ import * as random from "./libRandom.js";
88import * as zlib from "node:zlib" ;
99import * as fs from "node:fs" ;
1010import * as dns from "node:dns" ;
11+ import * as child from "node:child_process" ;
1112
1213export { md , pic , encode , random } ;
1314const html2mdFix = html2md . default ;
@@ -214,7 +215,7 @@ export async function lagacyProcess(input, processServerHost) {
214215 break ;
215216 }
216217 case 'pic' : {
217- let o = await pic . process ( c . data , input . url , processServerHost , input . opt , input . svgOpt ) ;
218+ let o = await pic . processLagacy ( c . data , input . url , processServerHost , input . opt , input . svgOpt ) ;
218219 if ( ! pics . includes ( o [ 0 ] . data ) ) pics . push ( o [ 0 ] . data ) ;
219220 out = out . concat ( o ) ;
220221 break ;
@@ -406,4 +407,144 @@ export function loadCookie(host,cookieDir){
406407 //thost.shift();
407408 }
408409 return out ;
410+ }
411+
412+ export async function viewPic ( url ) {
413+ console . log ( '[viewPic] view' , url ) ;
414+ var id = random . randomUUID ( ) ;
415+ var fn = ( url . startsWith ( 'https://' ) || url . startsWith ( 'http://' ) ) ? `file:///tmp/${ id } .png` : url ;
416+ var code = `
417+ import QtQuick 2.15
418+ import QtQuick.Controls 1.0
419+ import QtQuick.Layouts 1.15
420+
421+ ApplicationWindow {
422+ id: root
423+ visible: true
424+ width: 320
425+ height: 170
426+ title: "Image Viewer"
427+ color: "black"
428+ flags: Qt.FramelessWindowHint
429+ Rectangle {
430+ id: imageArea
431+ color: "black"
432+ width: parent.width*0.9
433+ height: parent.height
434+ x: parent.width*0.1
435+ y:0
436+ Image {
437+ id: imageViewer
438+ x:0
439+ y:0
440+ scale: 1
441+ source: "${ fn } "
442+ fillMode: Image.PreserveAspectFit
443+ }
444+ MouseArea {
445+ id: dragArea
446+ anchors.fill: parent
447+ drag.target: imageViewer
448+ drag.axis: Drag.XAndYAxis
449+
450+ }
451+ }
452+ Rectangle {
453+ color: "black"
454+ width: parent.width*0.1
455+ height: parent.height
456+ Button {
457+ text: "×"
458+ x: parent.width * 0.05
459+ y: parent.width * 0.05
460+ width: parent.width * 0.9
461+ height: parent.width * 0.9
462+ onClicked: Qt.quit()
463+
464+ }
465+ Button {
466+ text: "C"
467+ x: parent.width * 0.05
468+ y: parent.height - parent.width * 0.05*3 - parent.width * 0.9*3
469+ width: parent.width * 0.9
470+ height: parent.width * 0.9
471+ onClicked: {
472+ imageViewer.x = imageViewer.width * (imageViewer.scale-1) / 2;
473+ imageViewer.y = imageViewer.height * (imageViewer.scale-1) / 2;
474+ }
475+
476+ }
477+ Button {
478+ text: "+"
479+ x: parent.width * 0.05
480+ y: parent.height - parent.width * 0.05*2 - parent.width * 0.9*2
481+ width: parent.width * 0.9
482+ height: parent.width * 0.9
483+ onClicked: {
484+ imageViewer.scale = imageViewer.scale + 0.02;
485+ }
486+
487+ }
488+ Button {
489+ text: "-"
490+ x: parent.width * 0.05
491+ y: parent.height - parent.width * 0.05 - parent.width * 0.9
492+ width: parent.width * 0.9
493+ height: parent.width * 0.9
494+ onClicked: {
495+ if (imageViewer.scale - 0.02 > 0){
496+ imageViewer.scale = imageViewer.scale - 0.02;
497+ }else{
498+ imageViewer.scale = 0;
499+ }
500+ }
501+ }
502+ }
503+ }
504+ ` ;
505+ fs . writeFileSync ( `${ process . env [ 'ydpSysRootPath' ] } /tmp/image.qml` , code ) ;
506+ if ( ( url . startsWith ( 'https://' ) || url . startsWith ( 'http://' ) ) ) {
507+ var req = {
508+ context : {
509+ url : url ,
510+ ua : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36' ,
511+ cookie : '' ,
512+ refer : url
513+ } ,
514+ body : null ,
515+ method : 'GET' ,
516+ header : {
517+ 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' ,
518+ 'Sec-Ch-Ua' : '"Chromium";v="117", "Not)A;Brand";v="8", "Google Chrome";v="117"' ,
519+ 'Sec-Ch-Ua-Mobile' : '?0' ,
520+ 'Sec-Ch-Ua-Platform' : '"Linux"' ,
521+ 'Sec-Fetch-Dest' : 'document' ,
522+ 'Sec-Fetch-Mode' : 'navigate' ,
523+ 'Sec-Fetch-Site' : 'none' ,
524+ 'Sec-Fetch-User' : '?1' ,
525+ 'Upgrade-Insecure-Requests' : '1' ,
526+ 'Accept-Language' : 'zh-CN,zh;q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6' ,
527+ 'Cache-Control' : 'max-age=0'
528+ }
529+ } ;
530+ var data = await fetch ( req ) ;
531+ if ( data . body == null ) throw 'not any data received' ;
532+ fs . writeFileSync ( `${ process . env [ 'ydpSysRootPath' ] } /tmp/${ id } .png` , await pic . ffmpegDecodeToPng ( data . body , 'pic' ) ) ;
533+ }
534+ var imageViewer = child . spawn ( 'chroot' , [ '.' , 'qml' , `/tmp/image.qml` ] , { cwd :`${ process . env [ 'ydpSysRootPath' ] } ` } ) ;
535+ var outTxt = '' ;
536+ imageViewer . on ( 'close' , ( c ) => {
537+ fs . unlinkSync ( `${ process . env [ 'ydpSysRootPath' ] } /tmp/${ id } .png` ) ;
538+ fs . unlinkSync ( `${ process . env [ 'ydpSysRootPath' ] } /tmp/image.qml` ) ;
539+ console . log ( '[viewPic] process exit with code' , c , '.\n' , outTxt ) ;
540+ } ) ;
541+ imageViewer . on ( 'error' , ( e ) => {
542+ console . log ( '[viewPic] err\n' , e ) ;
543+ } ) ;
544+ imageViewer . stdout . on ( 'data' , ( d ) => {
545+ outTxt += String ( d ) ;
546+ } ) ;
547+ imageViewer . stderr . on ( 'data' , ( d ) => {
548+ outTxt += String ( d ) ;
549+ } ) ;
409550}
0 commit comments