How to use handleString method in wpt

Best JavaScript code snippet using wpt

aacDetails.js

Source:aacDetails.js Github

copy

Full Screen

12 //查看详情3function viewDetails(id,region_id ) {4 clearReportDetails();5 $("#info_dialog").dialog('open');6 //$("#detils_starttime").html("2017-03-07 15:39");7 $.ajax({8 url: "/AAC/GetReportDetailsById",9 type: "post",10 data: "reportid=" + id ,11 datatype: 'json',12 async: true,13 //beforeSend: function (XMLHttpRequest) {14 // $('#report_dg').datagrid('loading', "正在加载...");15 //},16 success: function (data) {17 if (data.status == 1) {18 alert("接处警详情加载出现" + data.msg + "错误请联系管理员!");19 }20 else21 if (data.msg != null) {22 var reportdata;//接处警详情23 reportdata = data.msg;24 //接警信息25 //reportdata.report.report_text.substring(0, 15);26 $("#detils_starttime").html(Util.changeDateFormat(reportdata.report.report_time));27 $("#detils_person_name").html(reportdata.report.report_person_name);28 $("#detils_report_text").html(reportdata.report.report_text.substring(0, 10) + "......");29 document.getElementById('report_show').onclick = function () {30 showudataReport(reportdata.report.id);31 };//接警查看事件 showReportDetails32 33 if (reportdata.total > 0) {//处警条数reportdata.reportinfo.id,34 for (var i = 0; i < reportdata.total; i++) {35 if (reportdata.handle[i].handle_type == 2) {36 addHandleEndDetails(reportdata.report.id, reportdata.handle[i].id, reportdata.report.report_num, region_id);//结案详情37 $("#detils_handletime_end").html(Util.changeDateFormat(reportdata.handle[i].record_time));38 $("#detils_handle_text_end").html(reportdata.handle[i].handle_text.substring(0, 15) + "......");39 40 continue;41 }42 if (i == 0) {43 addHandleStartDetails(reportdata.report.id, reportdata.handle[0].id, reportdata.report.report_num, region_id);44 $("#detils_handletime_1").html(Util.changeDateFormat(reportdata.handle[0].record_time));45 $("#detils_handle_text_1").html(reportdata.handle[0].handle_text.substring(0, 15) + "......");46 47 }48 else {49 var handle_num = addHandleDetails(reportdata.report.id, reportdata.handle[i].id, reportdata.report.report_num, region_id);//添加tr50 $("#detils_handletime_" + handle_num).html(Util.changeDateFormat(reportdata.handle[i].record_time));51 $("#detils_handle_text_" + handle_num).html(reportdata.handle[i].handle_text.substring(0, 15) + "......");52 }53 }54 //reportdata.handle;//处警内容55 }56 57 }58 },59 error: function (XMLHttpRequest, textStatus, errorThrown) {60 alert("接处警详情加载出现" + XMLHttpRequest.status + "错误请联系管理员!");61 }62 });63 }64 function aac() {65 alert("点击");66 }67 //添加接处警详情中的处警html68 function addHandleDetails(details_reportid, details_handleid, report_num, region_id) {69 //获取详情的table70 var table = document.getElementById("details_table");71 var rows = table.rows;72 //取到最后一个tr的编号73 var tablearr = (rows[rows.length - 2].id).split("_");74 var handle_id_num = Number(tablearr[tablearr.length - 1]);75 var handlestring = '';76 77 handlestring += '<tr id="detils_handle_' + (handle_id_num + 1) + '">';78 handlestring += '<td id="detils_handle_start_td" class="vT firstTd" width="80">';79 handlestring += '<p class="aacDetilsBg-p1" style="visibility: hidden;"></p>';80 handlestring += '<div class="aacLine"><div class="aacRound"></div></div>';81 handlestring += '</td>';82 handlestring += '<td id="detils_handle_1" class="vT">';83 handlestring += '<div class="detailsDiv">';84 handlestring += '<p><span id="detils_handletime_' + (handle_id_num + 1) + '">0000-00-00 00:00:00</span>&ensp;<img src="../style/base/images/public/aacLine.png" /></p>';85 handlestring += '<div class="aacInnerTab">';86 handlestring += '<table>';87 handlestring += '<tr>';88 handlestring += '<td width="90">处警操作:</td>';89 handlestring += '<td id="detils_person_name" width="90"></td>';90 handlestring += '<td id="report_details_btn" width="60">';91 handlestring += '<div class="detils-btn detils-look"onclick="showHandleDialog(' + details_reportid + ',' + details_handleid + ',' + report_num + ')"><img src="../style/base/images/public/frame/detils-look.png" />查看</div>';92 handlestring += '</td>';93 if (Number(region_id) == Number(regionId)) {94 handlestring += '<td id="report_details_btn" width="60">';95 handlestring += '<div class="detils-btn detils-chang"onclick="readHandleInfo(' + details_reportid + ',' + details_handleid + ',' + report_num + ',' + region_id + ')"><img src="../style/base/images/public/frame/detils-chang.png" />修改</div>';96 handlestring += '</td>';97 handlestring += '<td id="report_details_btn" width="60">';98 handlestring += '<div class="detils-btn detils-delete" onclick="delHandleInfo(' + details_reportid + ',' + details_handleid + ',' + report_num + ',' + region_id + ') "><img src="../style/base/images/public/frame/detils-delete.png" />删除</div>';99 handlestring += '</td>';100 }101 else {102 handlestring += '<td id="report_details_btn" width="60">';103 handlestring += '<div class="detils-btn detils-chang"></div>';104 handlestring += '</td>';105 handlestring += '<td id="report_details_btn" width="60">';106 handlestring += '<div class="detils-btn detils-delete" ></div>';107 handlestring += '</td>';108 }109 handlestring += '</tr>';110 handlestring += '<tr>';111 handlestring += '<td class="vAlignTop">处警内容:</td>';112 handlestring += '<td id="detils_handle_text_' + (handle_id_num + 1) + '" colspan="4" class="report-text">无</td>';113 handlestring += '</tr>';114 //handlestring += '<tr>';115 //handlestring += '<td>关联文件:</td>';116 //handlestring += '<td colspan="4">';117 //handlestring += '<div class="detils-btn detils-down" >下载</div>';118 //handlestring += '</td>';119 //handlestring += '</tr>';120 handlestring += '</table>';121 handlestring += '</div>';122 handlestring += '</div>';123 handlestring += '</td>';124 handlestring += '</tr>';125 //把新建的form添加到最后一个form后面126 $("#detils_handle_" + handle_id_num).after(handlestring);127 return (handle_id_num + 1);128 }129 //添加接处警详情中的第一条处警信息130 function addHandleStartDetails(details_reportid, details_handleid, report_num, region_id) {131 var handlestring = '';132 handlestring += '<td id="detils_handle_start" class="vT">';133 handlestring += '<div class="detailsDiv">';134 handlestring += '<p><span id="detils_handletime_1">0000-00-00 00:00:00</span>&ensp;<img src="../style/base/images/public/aacLine.png" /></p>';135 handlestring += '<div class="aacInnerTab">';136 handlestring += '<table>';137 handlestring += '<tr>';138 handlestring += '<td width="90">处警操作:</td>';139 handlestring += '<td id="detils_person_name" width="90"></td>';140 handlestring += '<td id="report_details_btn" width="60">';141 handlestring += '<div class="detils-btn detils-look" onclick="showHandleDialog(' + details_reportid + ',' + details_handleid + ',' + report_num + ')"><img src="../style/base/images/public/frame/detils-look.png" />查看</div>';142 handlestring += '</td>';143 if (Number(region_id) == Number(regionId)) {144 handlestring += '<td id="report_details_btn" width="60">';145 handlestring += '<div class="detils-btn detils-chang" onclick="readHandleInfo(' + details_reportid + ',' + details_handleid + ',' + report_num + ',' + region_id + ')"><img src="../style/base/images/public/frame/detils-chang.png" />修改</div>';146 handlestring += '</td>';147 handlestring += '<td id="report_details_btn" width="60">';148 handlestring += '<div class="detils-btn detils-delete" onclick="delHandleInfo(' + details_reportid + ',' + details_handleid + ',' + report_num + ',' + region_id + ') "><img src="../style/base/images/public/frame/detils-delete.png" />删除</div>';149 handlestring += '</td>';150 }151 else {152 handlestring += '<td id="report_details_btn" width="60">';153 handlestring += '<div class="detils-btn detils-chang" ></div>';154 handlestring += '</td>';155 handlestring += '<td id="report_details_btn" width="60">';156 handlestring += '<div class="detils-btn detils-delete" ></div>';157 handlestring += '</td>';158 }159 handlestring += '</tr>';160 handlestring += '<tr>';161 handlestring += '<td class="vAlignTop">处警内容:</td>';162 handlestring += '<td id="detils_handle_text_1" colspan="4" class="report-text">无</td>';163 handlestring += '</tr>';164 //handlestring += '<tr>';165 //handlestring += '<td>关联文件:</td>';166 //handlestring += '<td colspan="4">';167 //handlestring += '<div class="detils-btn detils-down" >下载</div>';168 //handlestring += '</td>';169 //handlestring += '</tr>';170 handlestring += '</table>';171 handlestring += '</div>';172 handlestring += '</div>';173 handlestring += '</td>';174 $("#detils_handle_start_td").after(handlestring);175 }176 //添加接处警详情中的结案html177 function addHandleEndDetails(details_reportid, details_handleid, report_num, region_id) {178 var handlestring = '';179 handlestring += '<td id="detils_handle_end" class="vT">';180 handlestring += '<div class="detailsDiv">';181 handlestring += '<p><span id="detils_handletime_end">0000-00-00 00:00:00</span>&ensp;<img src="../style/base/images/public/aacLine.png" /></p>';182 handlestring += '<div class="aacInnerTab">';183 handlestring += '<table>';184 handlestring += '<tr>';185 handlestring += '<td width="90">结案操作:</td>';186 handlestring += '<td id="detils_person_name" width="90"></td>';187 handlestring += '<td id="report_details_btn" width="60">';188 handlestring += '<div class="detils-btn detils-look" onclick="showHandleDialog(' + details_reportid + ',' + details_handleid + ',' + report_num + ')"><img src="../style/base/images/public/frame/detils-look.png" />查看</div>';189 handlestring += '</td>';190 if (Number(region_id) == Number(regionId)) {191 handlestring += '<td id="report_details_btn" width="60">';192 handlestring += '<div class="detils-btn detils-chang" onclick="readHandleInfo(' + details_reportid + ',' + details_handleid + ',' + report_num + ',' + region_id + ')"><img src="../style/base/images/public/frame/detils-chang.png" />修改</div>';193 handlestring += '</td>';194 handlestring += '<td id="report_details_btn" width="60">';195 handlestring += '<div class="detils-btn detils-delete"onclick="delHandleInfo(' + details_reportid + ',' + details_handleid + ',' + report_num + ',' + region_id + ') "><img src="../style/base/images/public/frame/detils-delete.png" />删除</div>';196 handlestring += '</td>';197 }198 else {199 handlestring += '<td id="report_details_btn" width="60">';200 handlestring += '<div class="detils-btn detils-chang" ></div>';201 handlestring += '</td>';202 handlestring += '<td id="report_details_btn" width="60">';203 handlestring += '<div class="detils-btn detils-delete"></div>';204 handlestring += '</td>';205 }206 handlestring += '</tr>';207 handlestring += '<tr>';208 handlestring += '<td>结案内容:</td>';209 handlestring += '<td id="detils_handle_text_end" colspan="4">无</td>';210 handlestring += '</tr>';211 //handlestring += '<tr>';212 //handlestring += '<td>关联文件:</td>';213 //handlestring += '<td colspan="4">';214 //handlestring += '<div class="detils-btn detils-down" >下载</div>';215 //handlestring += '</td>';216 //handlestring += '</tr>';217 handlestring += '</table>';218 handlestring += '</div>';219 handlestring += '</div>';220 handlestring += '</td>';221 //把新建的form添加到最后一个form后面222 $("#detils_handle_end_td").after(handlestring);223 }224 //查看接警信息225 function readReportInfo(id) {226 if (id == 0) { alert("未找到对应接警信息!"); return;}227 $("#updata_dialog").dialog('open');228 }229 230 ////查看处警信息231 //function readHandleInfo(id) {232 // $("#handle_dialog").dialog('open');233 //}234 //清空详情弹窗所有信息235 function clearReportDetails() {236 //$("#detils_starttime").html("");237 //$("#detils_person_name").html("");238 //获取详情的table239 var table = document.getElementById("details_table");240 var rows = table.rows;241 //取到最后一个tr的编号242 var tablearr = (rows[rows.length - 2].id).split("_");243 var handle_id_num = Number(tablearr[tablearr.length - 1]);244 var rowlength = rows.length;245 for (var i = 0; i < rowlength; i++) {246 if (i == 0) {//清空接警信息247 $("#detils_starttime").html("0000-00-00 00:00:00");248 $("#detils_person_name").html("无");249 $("#detils_report_text").html("无");250 $("#report_download").html('<a onclick="">下载</a>');251 // var loadingbtn = '<input type="button" onclick="readReportInfo(' + 0 + ')" value="查看">';252 // $("#report_details_btn").html(loadingbtn);253 continue;254 }255 if (i == 1) {256 if ($("#detils_handle_start").val() != undefined) {257 $("#detils_handle_start").remove();258 }259 continue;260 }261 if (i == (rowlength - 1)) {//清空结案信息262 if ($("#detils_handle_end").val() != undefined) {263 $("#detils_handle_end").remove();264 }265 continue;266 }267 if ((rows[i].id).indexOf("detils_handle_") > -1) {268 $("#" + rows[i].id).remove();269 }270 }...

Full Screen

Full Screen

sftp.ts

Source:sftp.ts Github

copy

Full Screen

1import * as ssh2 from "ssh2";2import * as fs from "fs";3import { Writable, Stream, Readable } from "stream";4import { Attributes, FileEntry, SFTPStream } from "ssh2-streams";5import { logger } from "../utils/logger";6import { noHandler } from "./common";7import { join } from 'path';8var openFiles: {9 [id: string]: { stream: Stream; fileHandle: string };10} = {};11var openDirs: { [id: string]: any } = {};12export const addSftpStreamHandlers = (sftpStream: SFTPStream) => {13 sftpStream.on("OPEN", openHandler(sftpStream));14 sftpStream.on("WRITE", writeHandler(sftpStream));15 sftpStream.on("CLOSE", closeHandler(sftpStream));16 sftpStream.on("FSTAT", fstatHandler(sftpStream));17 sftpStream.on("READDIR", readDirHandler(sftpStream));18 sftpStream.on("RENAME", renameHandler(sftpStream));19 sftpStream.on("REMOVE", removeHandler(sftpStream));20 sftpStream.on("READ", readHandler(sftpStream));21 sftpStream.on("OPENDIR", openDirHandler(sftpStream));22 sftpStream.on("REALPATH", realPathHandler(sftpStream));23 sftpStream.on("READLINK", noHandler("SFTPStream:readlink"));24 sftpStream.on("LSTAT", noHandler("SFTPStream:lstat"));25 sftpStream.on("STAT", statHandler(sftpStream));26 sftpStream.on("error", (err: any) => {27 logger.info(`Error from sftp is: ${err}`);28 });29};30let currentReadReqId: number;31const openHandler = (sftpStream: SFTPStream) => (32 reqId: number,33 filename: string,34 flags: number35) => {36 logger.info(`in open for ${filename}`);37 // only allow files of format '/<filename>.<ext>' or '/tmp/<filename>.<ext>'38 if (filename.substr(0, 5) === "/tmp/") {39 filename = "tmp/" + filename.substr(5).replace("/", "-");40 } else if (filename.substr(0, 4) === "tmp/") {41 filename = "tmp/" + filename.substr(4).replace("/", "-");42 } else {43 filename = filename.substr(1);44 filename = filename.replace("/", "-");45 }46 // Now set it to the location we want it to write to47 filename = "./sftp-server-files/" + filename;48 // Open mode returns basic stream49 let streamToWrite: Stream;50 logger.info(`Flags: ${flags}`);51 const stringFlags = SFTPStream.flagsToString(flags);52 logger.info(`String flags: ${stringFlags}`);53 if (stringFlags.includes("w")) {54 logger.info("we writing.");55 streamToWrite = fs.createWriteStream(filename, { flags: "w" });56 } else if (stringFlags.includes("a")) {57 logger.info("we be appending.");58 streamToWrite = fs.createWriteStream(filename, { flags: "a" });59 } else if (stringFlags.includes("r")) {60 logger.info("jsut readin for this one.");61 streamToWrite = fs.createReadStream(filename);62 streamToWrite.on("error", (err) => {63 sftpStream.status(64 currentReadReqId,65 ssh2.SFTP_STATUS_CODE.FAILURE,66 err.toString()67 );68 });69 } else {70 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);71 }72 openFiles[filename] = {73 stream: streamToWrite,74 fileHandle: filename,75 };76 sftpStream.handle(reqId, Buffer.from(filename));77 logger.info(`${Date.now().toString()} Opening file for read`);78};79const writeHandler = (sftpStream: SFTPStream) => (80 reqId: number,81 handle: Buffer,82 offset: number,83 data: Buffer84) => {85 let handleString = handle.toString();86 logger.info(87 `in write for reqID: ${reqId}: ${handle.toString()} with data: ${data.toString()}`88 );89 if (!openFiles[handleString]) {90 logger.info("we failed.");91 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);92 }93 // fake the write94 (openFiles[handleString].stream as Writable).write(data, (error) => {95 if (error) {96 logger.info(`Error: ${JSON.stringify(error)}`);97 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);98 }99 logger.info("wrote the file");100 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.OK);101 });102};103const closeHandler = (sftpStream: SFTPStream) => (104 reqId: number,105 handle: Buffer106) => {107 let handleString = handle.toString();108 logger.info(`in close received handle: ${handleString}`);109 if (!openFiles[handleString] && !openDirs[handleString]) {110 logger.info("cannot find path.");111 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);112 }113 if (openFiles[handleString]) {114 logger.info(`Closing file: ${handle}`);115 if (openFiles[handleString].stream instanceof Readable) {116 (openFiles[handleString].stream as Readable).destroy();117 delete openFiles[handleString];118 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.OK);119 } else {120 (openFiles[handleString].stream as Writable).end(null, () => {121 (openFiles[handleString].stream as Writable).destroy();122 delete openFiles[handleString];123 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.OK);124 });125 }126 } else {127 openDirs[handleString] = {};128 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.OK);129 }130};131const fstatHandler = (sftpStream: SFTPStream) => (132 reqId: number,133 handle: Buffer134) => {135 logger.info("in fstat");136 logger.info(`Trying to stat: ${handle}`);137 let handleString = handle.toString();138 if (!openFiles[handleString]) {139 logger.info("File not opened to stat.");140 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);141 }142 logger.info(`Stating file: ${handle}`);143 fs.open(openFiles[handleString].fileHandle, "r", (err, fd) => {144 if (err) {145 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);146 }147 fs.fstat(fd, (err, stats) => {148 if (err) {149 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);150 }151 const sftpStats: Attributes = {152 mode: stats.mode,153 uid: stats.uid,154 gid: stats.gid,155 size: stats.size,156 atime: stats.atime.valueOf(),157 mtime: stats.mtime.valueOf(),158 };159 logger.info(JSON.stringify(sftpStats));160 sftpStream.attrs(reqId, sftpStats);161 });162 });163};164const statHandler = (sftpStream: SFTPStream) => (165 reqId: number,166 handle: Buffer167) => {168 logger.info("in stat");169 logger.info(`Trying to stat: ${handle}`);170 let handleString = handle.toString();171 const rootDir = join(__dirname, '..', '..', 'sftp-server-files');172 handleString = join(rootDir, handleString);173 fs.stat(handleString, (err, stats) => {174 if (err) {175 logger.debug(`stat error: ${err}`)176 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);177 }178 const sftpStats: Attributes = {179 mode: stats.mode,180 uid: stats.uid,181 gid: stats.gid,182 size: stats.size,183 atime: stats.atime.valueOf(),184 mtime: stats.mtime.valueOf(),185 };186 logger.info(JSON.stringify(sftpStats));187 sftpStream.attrs(reqId, sftpStats);188 });189};190const readDirHandler = (sftpStream: SFTPStream) => (191 reqId: number,192 handle: Buffer193) => {194 logger.info("in readdir");195 let handleString = handle.toString();196 logger.info(`Trying to readdir: ${handleString}`);197 if (!openDirs[handleString]) {198 logger.info("File not opened to stat.");199 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);200 }201 logger.info(`Stating to read file dir: ${handle}`);202 let fileEntryList: FileEntry[] = [];203 try {204 const files = fs.readdirSync(handleString);205 logger.info(`Files: ${files.join("|")}`);206 for (let file of files) {207 if (openDirs[handleString][file]) {208 continue;209 }210 openDirs[handleString][file] = true;211 const fd = fs.openSync(handleString + "/" + file, "r");212 const fileAttributes = fs.fstatSync(fd);213 const sftpStats: Attributes = {214 mode: fileAttributes.mode,215 uid: fileAttributes.uid,216 gid: fileAttributes.gid,217 size: fileAttributes.size,218 atime: fileAttributes.atime.valueOf(),219 mtime: fileAttributes.mtime.valueOf(),220 };221 let longname: string;222 if (file === "tmp") {223 longname = "drwxrwxrwx";224 } else {225 longname = "-rwxrwxrwx";226 }227 longname = longname + " 1 user group 11 Sep 27 12:00 " + file;228 fileEntryList.push({229 filename: file,230 longname: longname,231 attrs: sftpStats,232 });233 }234 } catch (err) {235 logger.info(`Error getting file states: ${JSON.stringify(err)}`);236 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);237 }238 if (fileEntryList.length > 0) {239 logger.info("Files to return to client.");240 return sftpStream.name(reqId, fileEntryList);241 }242 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.EOF);243};244const renameHandler = (sftpStream: SFTPStream) => (245 reqId: number,246 oldPath: string,247 newPath: string248) => {249 logger.info(`${Date.now().toString()} Renaming`);250 if (oldPath.substr(0, 5) === "/tmp/") {251 oldPath = "tmp/" + oldPath.substr(5).replace("/", "-");252 } else {253 oldPath = oldPath.substr(1);254 oldPath = oldPath.replace("/", "-");255 }256 // Now set it to the location we want it to write to257 oldPath = "./sftp-server-files/" + oldPath;258 if (newPath.substr(0, 5) === "/tmp/") {259 newPath = "tmp/" + newPath.substr(5).replace("/", "-");260 } else {261 newPath = newPath.substr(1);262 newPath = newPath.replace("/", "-");263 }264 // Now set it to the location we want it to write to265 newPath = "./sftp-server-files/" + newPath;266 try {267 fs.renameSync(oldPath, newPath);268 sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.OK);269 } catch (err: any) {270 sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE, err.message);271 }272};273const removeHandler = (sftpStream: SFTPStream) => (274 reqId: number,275 path: string276) => {277 if (path.substr(0, 5) === "/tmp/") {278 path = "tmp/" + path.substr(5).replace("/", "-");279 } else {280 path = path.substr(1);281 path = path.replace("/", "-");282 }283 // Now set it to the location we want it to write to284 path = "./sftp-server-files/" + path;285 logger.info(`Trying to delete path: ${path}`);286 try {287 fs.unlinkSync(path);288 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.OK);289 } catch (err) {290 logger.info(`Error occured: ${err}`);291 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);292 }293};294const readHandler = (sftpStream: SFTPStream) => (295 reqId: number,296 handle: Buffer,297 offset: number,298 length: number299) => {300 let handleString = handle.toString();301 logger.info(302 `in read for reqID: ${reqId}: ${handle.toString()} with data length: ${length}`303 );304 if (!openFiles[handleString]) {305 logger.info("we failed.");306 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE);307 }308 // Just read the heck from it309 currentReadReqId = reqId;310 const dataRead = (openFiles[handleString].stream as Readable).read(length);311 if (!dataRead || dataRead.length === 0 || dataRead[0] === null) {312 // let handlers send the response.313 return sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.EOF);314 }315 return sftpStream.data(reqId, dataRead);316};317const openDirHandler = (sftpStream: SFTPStream) => (318 reqId: number,319 path: string320) => {321 logger.info("in opendir.");322 // only allow files of format '/<filename>.<ext>' or '/tmp/<filename>.<ext>'323 if (path[0] !== "/") {324 path = "/" + path;325 }326 // Now set it to the location we want it to write to327 path = "./sftp-server-files" + path;328 logger.info(`Opened path: ${path}`);329 openDirs[path] = {};330 sftpStream.handle(reqId, Buffer.from(path));331};332const realPathHandler = (sftpStream: SFTPStream) => (333 reqId: number,334 path: string335) => {336 logger.info(`in realpath: ${reqId} for ${path}`);337 try {338 if (path[0] !== "/") {339 path = "/" + path;340 }341 const realPathResult = fs.realpathSync("sftp-server-files" + path);342 logger.info(`Real path: ${realPathResult}`);343 if (!realPathResult.includes("sftp-server-files")) {344 throw new Error("Not a valid path on this server.");345 } else {346 const fd = fs.openSync(realPathResult, "r");347 const fileAttributes = fs.fstatSync(fd);348 const sftpStats: Attributes = {349 mode: fileAttributes.mode,350 uid: fileAttributes.uid,351 gid: fileAttributes.gid,352 size: fileAttributes.size,353 atime: fileAttributes.atime.valueOf(),354 mtime: fileAttributes.mtime.valueOf(),355 };356 logger.info(`Stats for file path: ${JSON.stringify(sftpStats)}`);357 const pathIndex = realPathResult.indexOf("sftp-server-files");358 let subFilePath: string;359 if (pathIndex + 17 >= realPathResult.length) {360 subFilePath = "/";361 } else {362 subFilePath = realPathResult.slice(pathIndex + 17);363 }364 logger.info(`Final path: ${subFilePath}`);365 sftpStream.name(reqId, [366 {367 filename: subFilePath,368 longname: subFilePath + "/",369 attrs: sftpStats,370 },371 ]);372 }373 } catch (err: any) {374 logger.info(`Real path error: ${JSON.stringify(err)}`);375 sftpStream.status(reqId, ssh2.SFTP_STATUS_CODE.FAILURE, err.message);376 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...24 if (_.isEmpty(this.props.rentals.data))25 this.props.dispatch(actions.fetchRentals());26 else {27 const params = new URLSearchParams(this.props.location.search);28 const key = handleString(params.get('key'));29 const result = this.props.rentals.data.filter(i =>30 handleString(i.title).includes(key) ||31 handleString(i.city).includes(key) ||32 handleString(i.address).includes(key)33 )34 Promise.all(result).then(this.setState({rentals:result}))35 }36 }37 componentWillReceiveProps(nextProps) {38 const params = new URLSearchParams(nextProps.location.search);39 const key = handleString(params.get('key'));40 const result = nextProps.rentals.data.filter(i =>41 handleString(i.title).includes(key) ||42 handleString(i.city).includes(key) ||43 handleString(i.address).includes(key)44 )45 Promise.all(result).then(this.setState({rentals:result}))46 }47 render() {48 return (49 <Fragment>50 <div style={{minHeight:"400px"}} className="container">51 <h3 className="text-left title_h3 type1 animated fadeInLeft">Kết quả tìm kiếm</h3>52 <div id="sub_home" className="text-center ">53 <div className="container mg-top-20">54 <div className="row">55 {this.renderRentals()}56 </div>57 </div>...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9{10 "dependencies": {11 }12}13var wpt = require('wpt');14var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');15}, function(err, data) {16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});22var wpt = require('wpt');23var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');24}, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require("wpt");2wpt.handleString(url, function(err, data){3 if(err){4 console.log(err);5 } else {6 console.log(data);7 }8});9{ statusCode: 200,10var wpt = require("wpt");11wpt.handleJSON(url, function(err, data){12 if(err){13 console.log(err);14 } else {15 console.log(data);16 }17});18{ testId: '140422_1Y_1',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.handleString(url, function(data){3 console.log(data);4});5var wpt = require('wpt');6wpt.handleString(url, function(data){7 console.log(data);8});9var wpt = require('wpt');10wpt.handleString(url, function(data){11 console.log(data);12});13var wpt = require('wpt');14wpt.handleString(url, function(data){15 console.log(data);16});17var wpt = require('wpt');18wpt.handleString(url, function(data){19 console.log(data);20});21var wpt = require('wpt');22wpt.handleString(url, function(data){23 console.log(data);24});25var wpt = require('wpt');26wpt.handleString(url, function(data){27 console.log(data);28});29var wpt = require('wpt');30wpt.handleString(url, function(data){31 console.log(data);32});33var wpt = require('wpt');34wpt.handleString(url, function(data){35 console.log(data);36});37var wpt = require('wpt');38wpt.handleString(url, function(data){

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('./wptools.js');2var handleString = wptools.handleString;3var str = "I am a string";4console.log(handleString(str));5var handleString = function(str) {6 return str;7}8module.exports = {9}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2 if (err) {3 console.log(err);4 }5 console.log(data);6});7var wpt = require('wpt');8 if (err) {9 console.log(err);10 }11 console.log(data);12});13var wpt = require('wpt');14 if (err) {15 console.log(err);16 }17 console.log(data);18});19var wpt = require('wpt');20 if (err) {21 console.log(err);22 }23 console.log(data);24});25var wpt = require('wpt');26 if (err) {27 console.log(err);28 }29 console.log(data);30});31var wpt = require('wpt');32 if (err) {33 console.log(err);34 }35 console.log(data);36});37var wpt = require('wpt');38 if (err) {39 console.log(err);40 }41 console.log(data);42});43var wpt = require('wpt');44 if (err) {45 console.log(err);46 }47 console.log(data);48});49var wpt = require('wpt');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var handleString = wpt.handleString;3var string = 'This is a string';4handleString(string, function(err, data) {5 console.log(data);6});7var handleString = function(string, callback) {8 callback(null, 'This is a string');9}10module.exports = {11}12var wpt = require('wpt');13var handleString = wpt.handleString;14var string = 'This is a string';15handleString(string, function(err, data) {16 console.log(data);17});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful