mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-04-24 20:07:51 +00:00
fix apiKey error
This commit is contained in:
parent
f925f8bf43
commit
035c3c5e6d
@ -2,7 +2,6 @@ import {LitElement, html, css} from 'lit';
|
||||
import {render} from 'lit/html.js';
|
||||
import {Epml} from '../../../../epml.js';
|
||||
import * as zip from '@zip.js/zip.js';
|
||||
import {saveAs} from 'file-saver';
|
||||
import '@material/mwc-icon';
|
||||
import ShortUniqueId from 'short-unique-id';
|
||||
import {publishData} from '../../../utils/publish-image.js';
|
||||
@ -150,9 +149,7 @@ setOpenGifModal: { attribute: false }
|
||||
|
||||
if (changedProperties && changedProperties.has('currentCollection')) {
|
||||
if (this.mode === 'explore') {
|
||||
console.log(this.mySubscribedCollections, "subbed collections here");
|
||||
const subbedCollection = this.mySubscribedCollections.find((collection) => ((collection.name === this.currentCollection.name) && (collection.identifier === this.currentCollection.identifier)));
|
||||
console.log({subbedCollection});
|
||||
if (subbedCollection) {
|
||||
this.isSubscribed = true;
|
||||
} else {
|
||||
@ -179,7 +176,7 @@ setOpenGifModal: { attribute: false }
|
||||
let collectionObj = collection;
|
||||
try {
|
||||
const metaData = await parentEpml.request('apiCall', {
|
||||
url: `/arbitrary/metadata/GIF_REPOSITORY/${this.myAccountName}/${collection.identifier}`,
|
||||
url: `/arbitrary/metadata/GIF_REPOSITORY/${this.myAccountName}/${collection.identifier}?apiKey=${this.getApiKey()}`,
|
||||
});
|
||||
|
||||
collectionObj = {
|
||||
@ -212,13 +209,19 @@ setOpenGifModal: { attribute: false }
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
getApiKey() {
|
||||
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
|
||||
let apiKey = myNode.apiKey;
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
async getMoreExploreGifs() {
|
||||
try {
|
||||
const getAllGifCollections = await parentEpml.request('apiCall', {
|
||||
type: 'api',
|
||||
url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=20&offset=${
|
||||
this.pageNumber * 20
|
||||
}`,
|
||||
}&apiKey=${this.getApiKey()}`,
|
||||
});
|
||||
|
||||
const gifCollectionWithMetaData = await this.structureCollections(
|
||||
@ -239,7 +242,7 @@ setOpenGifModal: { attribute: false }
|
||||
try {
|
||||
return await parentEpml.request('apiCall', {
|
||||
type: 'api',
|
||||
url: `/lists/gifSubscribedRepos`,
|
||||
url: `/lists/gifSubscribedRepos?apiKey=${this.getApiKey()}`,
|
||||
});
|
||||
} catch (error) {}
|
||||
}
|
||||
@ -254,7 +257,7 @@ setOpenGifModal: { attribute: false }
|
||||
await parentEpml.request('apiCall', {
|
||||
type: 'api',
|
||||
method: 'POST',
|
||||
url: `/lists/gifSubscribedRepos`,
|
||||
url: `/lists/gifSubscribedRepos?apiKey=${this.getApiKey()}`,
|
||||
body: bodyToString,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -272,7 +275,7 @@ setOpenGifModal: { attribute: false }
|
||||
await parentEpml.request('apiCall', {
|
||||
type: 'api',
|
||||
method: 'DELETE',
|
||||
url: `/lists/gifSubscribedRepos`,
|
||||
url: `/lists/gifSubscribedRepos?apiKey=${this.getApiKey()}`,
|
||||
body: bodyToString,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -286,7 +289,7 @@ setOpenGifModal: { attribute: false }
|
||||
this.myAccountName = userName;
|
||||
if (this.myAccountName) {
|
||||
const getMyGifCollections = await parentEpml.request('apiCall', {
|
||||
url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=0&name=${this.myAccountName}`,
|
||||
url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=0&name=${this.myAccountName}&apiKey=${this.getApiKey()}`,
|
||||
});
|
||||
const gifCollectionWithMetaData = await this.structureCollections(
|
||||
getMyGifCollections
|
||||
@ -305,7 +308,7 @@ setOpenGifModal: { attribute: false }
|
||||
type: 'api',
|
||||
url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=20&offset=${
|
||||
this.pageNumber * 20
|
||||
}`,
|
||||
}&apiKey=${this.getApiKey()}`,
|
||||
});
|
||||
const gifCollectionWithMetaData = await this.structureCollections(
|
||||
getAllGifCollections
|
||||
@ -324,7 +327,7 @@ setOpenGifModal: { attribute: false }
|
||||
const identifier = splitCollection[1];
|
||||
try {
|
||||
const data = await parentEpml.request('apiCall', {
|
||||
url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=0&name=${name}&identifier=${identifier}`,
|
||||
url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=0&name=${name}&identifier=${identifier}&apiKey=${this.getApiKey()}`,
|
||||
});
|
||||
if (data.length > 0) {
|
||||
savedCollections.push(data[0]);
|
||||
@ -346,7 +349,7 @@ setOpenGifModal: { attribute: false }
|
||||
try {
|
||||
const getNames = await parentEpml.request('apiCall', {
|
||||
type: 'api',
|
||||
url: `/names/address/${recipient}`,
|
||||
url: `/names/address/${recipient}?apiKey=${this.getApiKey()}`,
|
||||
});
|
||||
|
||||
if (Array.isArray(getNames) && getNames.length > 0) {
|
||||
@ -400,7 +403,7 @@ setOpenGifModal: { attribute: false }
|
||||
this.isLoading = true;
|
||||
const userName = await this.getName(this.selectedAddress.address);
|
||||
const doesNameExist = await parentEpml.request('apiCall', {
|
||||
url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=0&name=${userName}&identifier=${this.newCollectionName}`,
|
||||
url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=0&name=${userName}&identifier=${this.newCollectionName}&apiKey=${this.getApiKey()}`,
|
||||
});
|
||||
|
||||
if (!userName) {
|
||||
@ -465,6 +468,7 @@ setOpenGifModal: { attribute: false }
|
||||
|
||||
const blobTobase = await blobToBase64(zipFileBlob);
|
||||
|
||||
|
||||
await publishData({
|
||||
registeredName: userName,
|
||||
file: blobTobase.split(',')[1],
|
||||
@ -488,7 +492,7 @@ setOpenGifModal: { attribute: false }
|
||||
let myCollection = await parentEpml.request(
|
||||
'apiCall',
|
||||
{
|
||||
url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=0&name=${userName}&identifier=${this.newCollectionName}`,
|
||||
url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=0&name=${userName}&identifier=${this.newCollectionName}&apiKey=${this.getApiKey()}`,
|
||||
}
|
||||
);
|
||||
if (myCollection.length > 0) {
|
||||
@ -509,7 +513,7 @@ setOpenGifModal: { attribute: false }
|
||||
};
|
||||
interval = setInterval(getAnswer, 5000);
|
||||
});
|
||||
saveAs(zipFileBlob, 'zipfile');
|
||||
|
||||
this.isLoading = false;
|
||||
this.setGifsLoading(false);
|
||||
this.mode = 'myCollection';
|
||||
@ -519,6 +523,8 @@ setOpenGifModal: { attribute: false }
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
parentEpml.request('showSnackBar', get('gifs.gchange12'));
|
||||
this.setGifsLoading(false);
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -552,8 +558,6 @@ setOpenGifModal: { attribute: false }
|
||||
}
|
||||
|
||||
render() {
|
||||
console.log(8, "chat gifs here");
|
||||
console.log('this.currentCollection', this.currentCollection);
|
||||
return html`
|
||||
<div class="gifs-container">
|
||||
<div class="gif-explorer-container">
|
||||
|
@ -68,6 +68,11 @@ class ChatGifsExplore extends LitElement {
|
||||
this.shadowRoot.getElementById('downObserver');
|
||||
this.elementObserver();
|
||||
}
|
||||
getApiKey() {
|
||||
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
|
||||
let apiKey = myNode.apiKey;
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
async searchCollections() {
|
||||
this.isSearched = true;
|
||||
@ -75,7 +80,7 @@ class ChatGifsExplore extends LitElement {
|
||||
this.exploreCollections = [];
|
||||
this.isLoading = true;
|
||||
const response = await parentEpml.request('apiCall', {
|
||||
url: `/arbitrary/resources/search?service=GIF_REPOSITORY&query=${this.searchCollectionName}&limit=0
|
||||
url: `/arbitrary/resources/search?service=GIF_REPOSITORY&query=${this.searchCollectionName}&limit=0&apiKey=${this.getApiKey()}
|
||||
`,
|
||||
});
|
||||
await new Promise((res) => {
|
||||
|
@ -1386,68 +1386,14 @@ class ChatPage extends LitElement {
|
||||
}
|
||||
|
||||
addGifs(gifs){
|
||||
console.log('gifs', gifs)
|
||||
this.gifsToBeAdded = [...this.gifsToBeAdded, ...gifs]
|
||||
console.log('this.gifsToBeAdded', this.gifsToBeAdded)
|
||||
}
|
||||
|
||||
setGifsLoading(props) {
|
||||
this.gifsLoading = props;
|
||||
}
|
||||
|
||||
async uploadGifCollection(){
|
||||
try {
|
||||
function blobToBase64(blob) {
|
||||
return new Promise((resolve, _) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => resolve(reader.result);
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
}
|
||||
const zipFileWriter = new zip.BlobWriter("application/zip");
|
||||
// Creates a TextReader object storing the text of the entry to add in the zip
|
||||
// (i.e. "Hello world!").
|
||||
const helloWorldReader = new zip.TextReader("Hello world!");
|
||||
|
||||
// Creates a ZipWriter object writing data via `zipFileWriter`, adds the entry
|
||||
// "hello.txt" containing the text "Hello world!" via `helloWorldReader`, and
|
||||
// closes the writer.
|
||||
const file = this.gifsToBeAdded[0]
|
||||
const file2 = this.gifsToBeAdded[1]
|
||||
const zipWriter = new zip.ZipWriter(zipFileWriter, { bufferedWrite: true });
|
||||
await zipWriter.add(file.name, new zip.BlobReader(file));
|
||||
await zipWriter.add(file2.name, new zip.BlobReader(file2));
|
||||
|
||||
await zipWriter.close();
|
||||
const zipFileBlob = await zipFileWriter.getData()
|
||||
const blobTobase = await blobToBase64(zipFileBlob)
|
||||
console.log({blobTobase})
|
||||
const userName = await this.getName(this.selectedAddress.address);
|
||||
if (!userName) {
|
||||
parentEpml.request('showSnackBar', get("chatpage.cchange27"));
|
||||
this.isLoading = false;
|
||||
return;
|
||||
}
|
||||
const id = this.uid();
|
||||
const identifier = `gif_${id}`;
|
||||
await publishData({
|
||||
registeredName: userName,
|
||||
file : blobTobase.split(',')[1],
|
||||
service: 'GIF_REPOSITORY',
|
||||
identifier: identifier,
|
||||
parentEpml,
|
||||
metaData: undefined,
|
||||
uploadType: 'zip',
|
||||
selectedAddress: this.selectedAddress,
|
||||
worker: this.webWorkerImage,
|
||||
isBase64: true
|
||||
})
|
||||
saveAs(zipFileBlob, 'zipfile');
|
||||
console.log({zipFileBlob})
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`
|
||||
@ -1502,7 +1448,7 @@ console.log({zipFileBlob})
|
||||
<chat-gifs
|
||||
class="chat-gifs"
|
||||
style=${this.openGifModal ? "display: flex;" : "display: none;"}
|
||||
.webWorkerImage=${this.webWorkerImage}
|
||||
.webWorkerImage=${this.webWorkerFile}
|
||||
.setGifsLoading=${(val) => this.setGifsLoading(val)}
|
||||
.sendMessage=${(val) => this._sendMessage(val)}
|
||||
.setOpenGifModal=${(val)=> this.setOpenGifModal(val)}>
|
||||
@ -2069,8 +2015,8 @@ console.log({zipFileBlob})
|
||||
if(this.webWorker){
|
||||
this.webWorker.terminate();
|
||||
}
|
||||
if(this.webWorkerImage){
|
||||
this.webWorkerImage.terminate();
|
||||
if(this.webWorkerFile){
|
||||
this.webWorkerFile.terminate();
|
||||
}
|
||||
if(this.editor){
|
||||
this.editor.destroy()
|
||||
|
@ -80,7 +80,6 @@ class ChatScroller extends LitElement {
|
||||
}
|
||||
|
||||
render() {
|
||||
console.log(5, "chat scroller here");
|
||||
let formattedMessages = this.messages.reduce((messageArray, message, index) => {
|
||||
const lastGroupedMessage = messageArray[messageArray.length - 1];
|
||||
let timestamp;
|
||||
|
@ -455,7 +455,6 @@ mwc-checkbox::shadow .mdc-checkbox::after, mwc-checkbox::shadow .mdc-checkbox::b
|
||||
>${translate('chatpage.cchange69')}</label>
|
||||
|
||||
<mwc-checkbox style="margin-right: -15px;" id="qChatShowAutoMsg" @click=${e => {
|
||||
console.log(e.target.checked)
|
||||
if(e.target.checked){
|
||||
window.parent.reduxStore.dispatch( window.parent.reduxAction.removeAutoLoadImageChat(this.chatId))
|
||||
return
|
||||
|
@ -52,6 +52,11 @@ constructor() {
|
||||
this.attempts = 0;
|
||||
this.maxAttempts = 5;
|
||||
}
|
||||
getApiKey() {
|
||||
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
|
||||
let apiKey = myNode.apiKey;
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
async _fetchImage() {
|
||||
this.attempts++;
|
||||
@ -62,7 +67,7 @@ async _fetchImage() {
|
||||
}, 1000)
|
||||
});
|
||||
try {
|
||||
const response = await fetch(this.gif.url);
|
||||
const response = await fetch(this.gif.url + `&apiKey=${this.getApiKey()}`);
|
||||
const data = await response.json();
|
||||
console.log({data});
|
||||
if (data.ok) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user