Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static site manager by content ids #704

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const modulePacks = {
//TODO: refactor modules config
module.exports = {
databaseModule: 'sql',
databaseConfig: {},
databaseConfig: {

},
storageConfig: {
implementation: process.env.STORAGE_MODULE || 'js-ipfs',
jsNode: {
Expand Down
2 changes: 1 addition & 1 deletion app/modules/communicator/fluence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = async (app: IGeesomeApp) => {
// let neighbours = await dhtApi.getNeighbours(client, nodeId, 'topic')
const fluenceService = new FluenceService(app.ms.accountStorage, {logLevel: null /*'debug'*/});
const peerId = await app.ms.accountStorage.getAccountPeerId('self');
if(peerId) {
if (peerId) {
await fluenceService.initClient({
type: "Ed25519",
source: peerId.privKey.bytes
Expand Down
2 changes: 1 addition & 1 deletion app/modules/content/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = (app: IGeesomeApp, contentModule: IGeesomeContentModule) => {
});

app.ms.api.onGet('content-by-storage-id/:contentStorageId', async (req, res) => {
res.send(await contentModule.getContentByStorageId(req.params.contentStorageId));
res.send(await contentModule.getContentByStorageAndUserId(req.params.contentStorageId, req.user.id));
});

app.ms.api.onGet('content-stats/*', async (req, res) => {
Expand Down
12 changes: 8 additions & 4 deletions app/modules/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function getModule(app: IGeesomeApp) {
return app.ms.database.getContentByStorageId(storageId);
}

getContentByStorageAndUserId(storageId, userId) {
return app.ms.database.getContentByStorageAndUserId(storageId, userId);
}

getContentByManifestId(storageId) {
return app.ms.database.getContentByManifestId(storageId);
}
Expand Down Expand Up @@ -87,7 +91,7 @@ function getModule(app: IGeesomeApp) {
let previewData = await this.getPreview({id: content.storageId, size: content.size}, content.extension, content.mimeType);
await app.ms.database.updateContent(content.id, previewData);
const updatedContent = await this.updateContentManifest({
...content['toJSON'](),
...content.toJSON() as any,
...previewData
});

Expand Down Expand Up @@ -309,7 +313,7 @@ function getModule(app: IGeesomeApp) {
if (propsToUpdate.some(prop => options[prop] && content[prop] !== options[prop])) {
await app.ms.database.updateContent(content.id, _.pick(options, propsToUpdate));
await this.updateContentManifest({
...content['toJSON'](),
...content.toJSON() as any,
..._.pick(options, propsToUpdate),
});
}
Expand All @@ -324,7 +328,7 @@ function getModule(app: IGeesomeApp) {
}
await app.ms.database.updateContent(content.id, updateData);
return this.updateContentManifest({
...content['toJSON'](),
...content.toJSON() as any,
...updateData,
});
}
Expand Down Expand Up @@ -718,7 +722,7 @@ function getModule(app: IGeesomeApp) {

async createContentByObject(userId, contentObject, options?: { userApiKeyId? }) {
const storageId = contentObject.manifestStaticStorageId || contentObject.manifestStorageId;
const dbContent = await app.ms.database.getContentByStorageId(storageId);
const dbContent = await app.ms.database.getContentByStorageAndUserId(storageId, userId);
if (dbContent) {
return dbContent;
}
Expand Down
2 changes: 2 additions & 0 deletions app/modules/content/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default interface IGeesomeContentModule {

getContentByStorageId(storageId): Promise<IContent>;

getContentByStorageAndUserId(storageId, userId): Promise<IContent>;

getContentByManifestId(storageId): Promise<IContent>;

createContentByObject(userId, contentObject, options?: { groupId?, userApiKeyId? }): Promise<IContent>;
Expand Down
14 changes: 7 additions & 7 deletions app/modules/database/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
const log = require('debug')('geesome:database');

module.exports = {
'name': 'geesome_node',
'user': 'geesome',
'password': 'geesome',
'name': process.env.DATABASE_PASSWORD || 'geesome_node',
'user': process.env.DATABASE_USER || 'geesome',
'password': process.env.DATABASE_DB || 'geesome',
'options': {
'logging': (d) => {/*log(d)*/},
'host': 'localhost',
// 'dialect': 'postgres',
'dialect': 'sqlite',
'storage': `${process.env.DATA_DIR || 'data'}/core.sqlite`
'host': process.env.DATABASE_HOST || 'localhost',
'dialect': 'postgres',
// 'dialect': 'sqlite',
// 'storage': `${process.env.DATA_DIR || 'data'}/core.sqlite`
}
};
4 changes: 4 additions & 0 deletions app/modules/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ class MysqlDatabase implements IGeesomeDatabaseModule {
return where;
}

getUserContentListByIds(userId, contentIds) {
return this.models.Content.findAll({where: {userId, id: {[Op.in]: contentIds}}});
}

async getAllContentList(searchString, listParams: IListParams = {}) {
this.setDefaultListParamsValues(listParams);
const {sortBy, sortDir, limit, offset} = listParams;
Expand Down
3 changes: 3 additions & 0 deletions app/modules/database/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface IGeesomeDatabaseModule {

getContentList(accountAddress, listParams?: IListParams): Promise<IContent[]>;

getUserContentListByIds(userId, contentIds): Promise<IContent[]>;

getContent(id): Promise<IContent>;

getContentByStorageId(storageId, findByPreviews?): Promise<IContent>;
Expand Down Expand Up @@ -169,6 +171,7 @@ export interface IContent {

encryptedManifestStorageId?: string;
propertiesJson?: string;
toJSON?(): string;
}

export interface IObject {
Expand Down
29 changes: 11 additions & 18 deletions app/modules/fileCatalog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ function getModule(app: IGeesomeApp, models) {
type = undefined;
}
console.log('userId', userId, 'parentItemId', parentItemId, 'type', type, 'search', search);

return {
list: await this.getFileCatalogItemsList(userId, parentItemId, type, search, listParams),
total: await this.getFileCatalogItemsCount(userId, parentItemId, type, search)
Expand Down Expand Up @@ -337,15 +336,12 @@ function getModule(app: IGeesomeApp, models) {

const {limit, offset, sortBy, sortDir} = listParams;
const where: any = {userId, type, isDeleted: false};

if (!_.isUndefined(parentItemId)) {
where.parentItemId = parentItemId;
}

if (search) {
where['name'] = {[Op.like]: search};
}

return models.FileCatalogItem.findAll({
where,
order: [[sortBy, sortDir.toUpperCase()]],
Expand All @@ -355,6 +351,17 @@ function getModule(app: IGeesomeApp, models) {
});
}

async getFileCatalogItemsCount(userId, parentItemId, type = null, search = '') {
const where: any = {userId, type, isDeleted: false};
if (!_.isUndefined(parentItemId)) {
where.parentItemId = parentItemId;
}
if (search) {
where['name'] = {[Op.like]: search};
}
return models.FileCatalogItem.count({where});
}

async getFileCatalogItemsByContent(userId, contentId, type = null, listParams: IListParams = {}) {
app.ms.database.setDefaultListParamsValues(listParams);
const {sortBy, sortDir, limit, offset} = listParams;
Expand All @@ -367,20 +374,6 @@ function getModule(app: IGeesomeApp, models) {
});
}

async getFileCatalogItemsCount(userId, parentItemId, type = null, search = '') {
const where: any = {userId, type, isDeleted: false};

if (!_.isUndefined(parentItemId)) {
where.parentItemId = parentItemId;
}

if (search) {
where['name'] = {[Op.like]: search};
}

return models.FileCatalogItem.count({where});
}

async isFileCatalogItemExistWithContent(userId, parentItemId, contentId) {
return models.FileCatalogItem.findOne({where: {userId, parentItemId, contentId}}).then(r => !!r);
}
Expand Down
2 changes: 1 addition & 1 deletion app/modules/pin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function getModule(app: IGeesomeApp, models) {
}

async pinByPinata(storageId: string, account: IPinAccount, options?) {
const content = await app.ms.content.getContentByStorageId(storageId);
const content = await app.ms.content.getContentByStorageAndUserId(storageId, account.userId);
const hostNodes = await app.ms.storage.remoteNodeAddressList(['tcp']);
console.log('hostNodes', hostNodes);
return axios
Expand Down
2 changes: 1 addition & 1 deletion app/modules/staticSiteGenerator/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = (_app: IGeesomeApp, ssgModule: IGeesomeStaticSiteGeneratorModul
return res.send(await ssgModule.getStaticSiteInfo(req.user.id, req.body.entityType, req.body.entityId), 200);
});
api.onAuthorizedPost('run', async (req, res) => {
return res.send(await ssgModule.addRenderToQueueAndProcess(req.user.id, req.apiKey.id, req.body.entityType, req.body.entityId, req.body.options), 200);
return res.send(await ssgModule.addRenderToQueueAndProcess(req.user.id, req.apiKey.id, _.pick(req.body, ['entityType', 'entityId']), req.body.options), 200);
});
api.onAuthorizedPost('bind-to-static-id/:id', async (req, res) => {
return res.send(await ssgModule.bindSiteToStaticId(req.user.id, req.params.id), 200);
Expand Down
Loading