From b8bf5df4e6c5079b4f7af1439b4e8add72ce2b6c Mon Sep 17 00:00:00 2001 From: Sukhamjot Singh Date: Sun, 19 Jun 2022 23:09:21 +0530 Subject: [PATCH] added open file,if present (not functional) --- webui-src/app/channels/channels_util.js | 56 +++++++++++++++++++------ 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/webui-src/app/channels/channels_util.js b/webui-src/app/channels/channels_util.js index 7d7717c..979f830 100644 --- a/webui-src/app/channels/channels_util.js +++ b/webui-src/app/channels/channels_util.js @@ -7,11 +7,10 @@ const GROUP_SUBSCRIBE_SUBSCRIBED = 0x04; // means: you are subscribed to a group const GROUP_SUBSCRIBE_NOT_SUBSCRIBED = 0x08; const GROUP_MY_CHANNEL = GROUP_SUBSCRIBE_ADMIN + GROUP_SUBSCRIBE_SUBSCRIBED + GROUP_SUBSCRIBE_PUBLISH; +const RS_FILE_REQ_ANONYMOUS_ROUTING = 0x00000040; // const GXS_VOTE_DOWN = 0x0001; // const GXS_VOTE_UP = 0x0002; - - const Data = { DisplayChannels: {}, Posts: {}, @@ -32,7 +31,6 @@ async function updateContent(content, channelid) { Data.Comments[content.mThreadId] = {}; } Data.Comments[content.mThreadId][content.mMsgId] = res.body.comments[0]; - // console.log(Data.Comments[content.mThreadId][content.mMsgId]); } } @@ -63,7 +61,6 @@ async function updateDisplayChannels(keyid, details) { channelId: keyid, }); - // console.log(res2); if (res2.body.retval) { res2.body.summaries.map((content) => { updateContent(content, keyid); @@ -133,7 +130,6 @@ const ChannelView = () => { lastActivity = Data.DisplayChannels[v.attrs.id].activity; } if (Data.Posts[v.attrs.id]) { - // console.log(Data.Posts[v.attrs.id]); plist = Data.Posts[v.attrs.id]; } }, @@ -257,20 +253,20 @@ const FilesTable = () => { ]), }; }; + function formatBytes(bytes, decimals = 2) { if (bytes === 0) return '0 Bytes'; - const k = 1024; const dm = decimals < 0 ? 0 : decimals; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - const i = Math.floor(Math.log(bytes) / Math.log(k)); - return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; } + const PostView = () => { let post = {}; let comments = {}; + const filesInfo = {}; return { oninit: (v) => { if (Data.Posts[v.attrs.channelId] && Data.Posts[v.attrs.channelId][v.attrs.msgId]) { @@ -279,6 +275,14 @@ const PostView = () => { if (Data.Comments[v.attrs.msgId]) { comments = Data.Comments[v.attrs.msgId]; } + if (post) { + post.mFiles.map(async (file) => { + const res = await rs.rsJsonApiRequest('/rsfiles/alreadyHaveFile', { + hash: file.mHash, + }); + filesInfo[file.mHash] = res.body; + }); + } }, view: (v) => m('.widget', { key: v.attrs.msgId }, [ @@ -305,13 +309,36 @@ const PostView = () => { m('tr', [ m('td', file.mName), m('td', formatBytes(file.mSize.xint64)), - m('button', 'Download', m('i.fas.fa-download')), + m( + 'button', + { + onclick: async () => { + filesInfo[file.mHash] + ? filesInfo[file.mHash].retval + ? '' + : await rs.rsJsonApiRequest('/rsFiles/FileRequest', { + fileName: file.mName, + hash: file.mHash, + flags: RS_FILE_REQ_ANONYMOUS_ROUTING, + size: { + xstr64: file.mSize.xstr64, + }, + }) + : ''; + }, + }, + filesInfo[file.mHash] + ? filesInfo[file.mHash].retval + ? 'Open File' + : ['Download', m('i.fas.fa-download')] + : '' + ), ]) ) ) ), m('hr'), - m('h3', 'Comments' + comments.length), + m('h3', 'Comments'), m( CommentsTable, m( @@ -320,9 +347,12 @@ const PostView = () => { m('tr', [ m('td', comments[key].mComment), m('td', rs.userList.userMap[comments[key].mMeta.mAuthorId]), - m('td', typeof comments[key].mMeta.mPublishTs === 'object' - ? new Date(comments[key].mMeta.mPublishTs.xint64 * 1000).toLocaleString() - : 'undefined'), + m( + 'td', + typeof comments[key].mMeta.mPublishTs === 'object' + ? new Date(comments[key].mMeta.mPublishTs.xint64 * 1000).toLocaleString() + : 'undefined' + ), ]) ) )