Skip to content
This repository has been archived by the owner on Dec 19, 2020. It is now read-only.

Commit

Permalink
fix content linking #49 and prepare contents data base for fulltext s…
Browse files Browse the repository at this point in the history
…earch #50
  • Loading branch information
MicrowaveDev committed Jun 24, 2019
1 parent 891600d commit a41c331
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async function restoreExtensionDataFromIpld(backupIpld) {

setInterval(() => {
saveExtensionDataAndBindToIpns();
}, 1000 * 60); //* 10
}, 1000 * 60 * 5);

fetchCurrentTab();

Expand Down Expand Up @@ -209,7 +209,7 @@ onMessage(async (request, sender, sendResponse) => {
.then(async data => {
setAction(null);

if (data.mimeType === 'text/html') {
if (data.mimeType === 'text/html' && !data.iconHash) {
const contentData = await ipfsService.getContent(data.contentHash);

const $ = cheerio.load(contentData);
Expand Down
8 changes: 7 additions & 1 deletion src/backgroundServices/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ const databaseService = {

db.version(1).stores({
content:
'++id,contentHash,manifestHash,description,keywords,size,mimeType,previewHash,previewMimeType,iconHash,iconMimeType,view,extension,previewExtension,createdAt,updatedAt',
'++id,contentHash,manifestHash,description,keywords,size,mimeType,previewHash,previewMimeType,iconHash,iconMimeType,view,extension,previewExtension,fullText,createdAt,updatedAt',
settings: 'name,value',
});
},
async saveContent(contentObj) {
const existingContent = await this.getContentByHash(contentObj.contentHash);

contentObj.fullText = (contentObj.description || (existingContent || {}).description || '').split(/[ ,.]+/);
contentObj.fullText = contentObj.fullText.concat(contentObj.keywords || (existingContent || {}).keywords || []);
contentObj.fullText = contentObj.fullText.filter(item => !item.match(/^[ ,.\-_/\\\(\)"'?]$/) && item != '');

if (existingContent) {
console.log('updateContentByHash', contentObj.contentHash, contentObj);
return this.updateContentByHash(contentObj.contentHash, contentObj).then(() => this.getContentByHash(contentObj.contentHash));
}
contentObj.createdAt = Helper.now();
Expand Down
15 changes: 12 additions & 3 deletions src/popup/pages/Cabinet/CyberDCabinet/LinkContent/LinkContent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppWallet, StorageVars } from '../../../../../services/data';
import { CyberD } from '../../../../../services/cyberd';
import { addIpfsContentArray } from '../../../../../services/backgroundGateway';
import { addIpfsContentArray, saveContent } from '../../../../../services/backgroundGateway';
import ContentDetails from '../../../../directives/ContentDetails/ContentDetails';

const pIteration = require('p-iteration');
Expand All @@ -13,6 +13,10 @@ export default {
},
methods: {
async link() {
console.log('this.inputKeywordsStr', this.inputKeywordsStr);
console.log('this.keywords', this.keywords);
console.log('this.resultKeywords', this.resultKeywords);
console.log('this.$route.query.keywords', this.$route.query.keywords);
const keywordHashes = await addIpfsContentArray(this.resultKeywords);

const results = await pIteration.mapSeries(keywordHashes, async keywordHash => {
Expand All @@ -26,6 +30,11 @@ export default {
);
});

await saveContent({
contentHash: this.resultContentHash,
keywords: this.resultKeywords,
});

console.log('link results', results);

this.$notify({
Expand All @@ -41,13 +50,13 @@ export default {
return this.contentHash || this.inputContentHash;
},
resultKeywords() {
return this.keywords || this.inputKeywordsStr.split(/[ ,]+/);
return this.inputKeywordsStr.split(/[ ,]+/);
},
contentHash() {
return this.$route.query.contentHash;
},
keywords() {
return _.isArray(this.$route.query.keywords) ? this.$route.query.keywords : (this.$route.query.keywords || '').split(/[ ,]+/);
return _.isArray(this.$route.query.keywords) ? this.$route.query.keywords : this.$route.query.keywords ? this.$route.query.keywords.split(/[ ,]+/) : null;
},
keywordsStr() {
return this.keywords ? this.keywords.join(', ') : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ export default {
return this.contentHash || this.inputContentHash;
},
resultKeywords() {
return this.keywords || this.inputKeywordsStr.split(/[ ,]+/);
return this.inputKeywordsStr.split(/[ ,]+/);
},
contentHash() {
return this.$route.query.contentHash;
},
keywords() {
return _.isArray(this.$route.query.keywords) ? this.$route.query.keywords : (this.$route.query.keywords || '').split(/[ ,]+/);
return _.isArray(this.$route.query.keywords) ? this.$route.query.keywords : this.$route.query.keywords ? this.$route.query.keywords.split(/[ ,]+/) : null;
},
keywordsStr() {
return this.keywords ? this.keywords.join(', ') : '';
Expand Down

0 comments on commit a41c331

Please sign in to comment.