@nina-protocol/nina-db 0.0.16 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/models/Hub.js +1 -144
- package/dist/models/Release.js +10 -2
- package/dist/models/Transaction.js +1 -0
- package/package.json +3 -3
- package/src/index.js +1 -1
- package/src/models/Hub.js +1 -147
- package/src/models/Release.js +10 -3
- package/src/models/Transaction.js +1 -0
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Model } from 'objection';
|
|
|
4
4
|
import Models from './models/index.js';
|
|
5
5
|
import knexConfig from './knexfile.js';
|
|
6
6
|
export const initDb = async (config) => {
|
|
7
|
-
const db = Knex(config);
|
|
7
|
+
const db = Knex(config.development);
|
|
8
8
|
await db.raw(`SELECT 'CREATE DATABASE ${process.env.POSTGRES_DATABASE}'
|
|
9
9
|
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${process.env.POSTGRES_DATABASE}')`);
|
|
10
10
|
await db.migrate.latest();
|
package/dist/models/Hub.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
1
|
import { Model } from 'objection';
|
|
3
|
-
import { stripHtmlIfNeeded
|
|
2
|
+
import { stripHtmlIfNeeded } from '../utils/index.js';
|
|
4
3
|
import Account from './Account.js';
|
|
5
4
|
import Release from './Release.js';
|
|
6
5
|
import Post from './Post.js';
|
|
@@ -31,148 +30,6 @@ export default class Hub extends Model {
|
|
|
31
30
|
delete this.id;
|
|
32
31
|
stripHtmlIfNeeded(this.data, 'description');
|
|
33
32
|
}
|
|
34
|
-
static async updateHub(hub, hubAccount, hubContents, hubReleases, hubCollaborators, hubPosts) {
|
|
35
|
-
if (typeof hubAccount.account.uri !== 'string') {
|
|
36
|
-
hubAccount.account.uri = decode(hubAccount.account.uri);
|
|
37
|
-
}
|
|
38
|
-
if (!hub.dataUri || hub.dataUri !== hubAccount.account.uri) {
|
|
39
|
-
const data = (await axios.get(hubAccount.account.uri)).data;
|
|
40
|
-
await hub.$query().patch({
|
|
41
|
-
data,
|
|
42
|
-
dataUri: hubAccount.account.uri
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
// Update Hub Releases
|
|
46
|
-
const hubReleasesForHubOnChain = hubReleases.filter(x => x.account.hub.toBase58() === hub.publicKey);
|
|
47
|
-
const hubReleasesForHubDb = (await Hub.relatedQuery('releases').for(hub)).map(x => x.publicKey);
|
|
48
|
-
const newHubReleasesForHub = hubReleasesForHubOnChain.filter(x => !hubReleasesForHubDb.includes(x.account.release.toBase58()));
|
|
49
|
-
for await (let hubRelease of hubReleasesForHubOnChain) {
|
|
50
|
-
try {
|
|
51
|
-
if (hubReleasesForHubDb.includes(hubRelease.account.release.toBase58())) {
|
|
52
|
-
const hubContent = hubContents.filter(x => x.account.child.toBase58() === hubRelease.publicKey.toBase58())[0];
|
|
53
|
-
const release = await Release.query().findOne({ publicKey: hubRelease.account.release.toBase58() });
|
|
54
|
-
if (release) {
|
|
55
|
-
await Hub.relatedQuery('releases').for(hub.id).patch({
|
|
56
|
-
visible: hubContent.account.visible,
|
|
57
|
-
}).where({ id: release.id });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
console.log(err);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
for await (let hubRelease of newHubReleasesForHub) {
|
|
66
|
-
try {
|
|
67
|
-
const hubContent = hubContents.filter(x => x.account.child.toBase58() === hubRelease.publicKey.toBase58())[0];
|
|
68
|
-
const release = await Release.query().findOne({ publicKey: hubRelease.account.release.toBase58() });
|
|
69
|
-
if (release) {
|
|
70
|
-
await Hub.relatedQuery('releases').for(hub.id).relate({
|
|
71
|
-
id: release.id,
|
|
72
|
-
hubReleasePublicKey: hubRelease.publicKey.toBase58(),
|
|
73
|
-
visible: hubContent.account.visible,
|
|
74
|
-
});
|
|
75
|
-
if (hubContent.account.publishedThroughHub) {
|
|
76
|
-
await release.$query().patch({ hubId: hub.id });
|
|
77
|
-
}
|
|
78
|
-
console.log('Related Release to Hub:', release.publicKey, hub.publicKey);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
console.log(err);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Update Hub Collaborators
|
|
86
|
-
const hubCollaboratorsForHubOnChain = hubCollaborators.filter(x => x.account.hub.toBase58() === hub.publicKey);
|
|
87
|
-
const hubCollaboratorsForHubDb = (await Hub.relatedQuery('collaborators').for(hub)).map(x => x.publicKey);
|
|
88
|
-
const newHubCollaboratorsForHub = hubCollaboratorsForHubOnChain.filter(x => !hubCollaboratorsForHubDb.includes(x.account.collaborator.toBase58()));
|
|
89
|
-
for await (let hubCollaborator of newHubCollaboratorsForHub) {
|
|
90
|
-
try {
|
|
91
|
-
const collaboratorRecord = await Account.findOrCreate(hubCollaborator.account.collaborator.toBase58());
|
|
92
|
-
if (collaboratorRecord) {
|
|
93
|
-
await Hub.relatedQuery('collaborators').for(hub.id).relate({
|
|
94
|
-
id: collaboratorRecord.id,
|
|
95
|
-
hubCollaboratorPublicKey: hubCollaborator.publicKey.toBase58(),
|
|
96
|
-
});
|
|
97
|
-
console.log('Related Collaborator to Hub:', collaboratorRecord.publicKey, hub.publicKey);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
console.log(err);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const removedCollaborators = hubCollaboratorsForHubDb.filter(x => !hubCollaboratorsForHubOnChain.map(x => x.account.collaborator.toBase58()).includes(x));
|
|
105
|
-
for await (let removedCollaborator of removedCollaborators) {
|
|
106
|
-
try {
|
|
107
|
-
const collaboratorRecord = await Account.query().findOne({ publicKey: removedCollaborator });
|
|
108
|
-
if (collaboratorRecord) {
|
|
109
|
-
await Hub.relatedQuery('collaborators').for(hub.id).unrelate().where('accountId', collaboratorRecord.id);
|
|
110
|
-
console.log('Removed Collaborator from Hub:', collaboratorRecord.publicKey, hub.publicKey);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
console.log(err);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
//Update HubPosts
|
|
118
|
-
const hubPostsForHubOnChain = hubPosts.filter(x => x.account.hub.toBase58() === hub.publicKey);
|
|
119
|
-
const hubPostsForHubDb = (await Hub.relatedQuery('posts').for(hub)).map(x => x.publicKey);
|
|
120
|
-
const newHubPostsForHub = hubPostsForHubOnChain.filter(x => !hubPostsForHubDb.includes(x.account.post.toBase58()));
|
|
121
|
-
for await (let hubPost of hubPostsForHubOnChain) {
|
|
122
|
-
try {
|
|
123
|
-
if (hubPostsForHubDb.includes(hubPost.account.post.toBase58())) {
|
|
124
|
-
const hubContent = hubContents.filter(x => x.account.child.toBase58() === hubPost.publicKey.toBase58())[0];
|
|
125
|
-
if (!hubContent.account.visible) {
|
|
126
|
-
const post = await Post.query().findOne({ publicKey: hubPost.account.post.toBase58() });
|
|
127
|
-
if (post) {
|
|
128
|
-
await Post.relatedQuery('releases').for(post.id).unrelate().where('hubId', hub.id);
|
|
129
|
-
console.log('Deleted Post:', hubPost.publicKey);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
catch (err) {
|
|
135
|
-
console.log(err);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
for await (let hubPost of newHubPostsForHub) {
|
|
139
|
-
try {
|
|
140
|
-
const hubContent = hubContents.filter(x => x.account.child.toBase58() === hubPost.publicKey.toBase58())[0];
|
|
141
|
-
const post = await Post.query().findOne({ publicKey: hubPost.account.post.toBase58() });
|
|
142
|
-
if (hubContent.account.visible) {
|
|
143
|
-
if (post) {
|
|
144
|
-
await Hub.relatedQuery('posts').for(hub.id).relate({
|
|
145
|
-
id: post.id,
|
|
146
|
-
hubPostPublicKey: hubPost.publicKey.toBase58(),
|
|
147
|
-
});
|
|
148
|
-
if (hubContent.account.publishedThroughHub) {
|
|
149
|
-
await post.$query().patch({ hubId: hub.id });
|
|
150
|
-
}
|
|
151
|
-
console.log('Related Post to Hub:', post.publicKey, hub.publicKey);
|
|
152
|
-
}
|
|
153
|
-
if (hubPost.account.referenceContent) {
|
|
154
|
-
const release = await Release.query().findOne({ publicKey: hubPost.account.referenceContent.toBase58() });
|
|
155
|
-
if (release) {
|
|
156
|
-
const relatedRelease = await Post.relatedQuery('releases').for(post.id).where('releaseId', release.id).first();
|
|
157
|
-
if (!relatedRelease) {
|
|
158
|
-
await Post.relatedQuery('releases').for(post.id).relate(release.id);
|
|
159
|
-
console.log('Related Release to Post:', release.publicKey, post.publicKey);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else if (post) {
|
|
165
|
-
if (hubContent.account.publishedThroughHub) {
|
|
166
|
-
await Post.query().deleteById(post.id);
|
|
167
|
-
console.log('deleted Post:', post.publicKey);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
console.log(err);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
33
|
static relationMappings = () => ({
|
|
177
34
|
authority: {
|
|
178
35
|
relation: Model.HasOneRelation,
|
package/dist/models/Release.js
CHANGED
|
@@ -6,6 +6,7 @@ import Account from './Account.js';
|
|
|
6
6
|
import Exchange from './Exchange.js';
|
|
7
7
|
import Hub from './Hub.js';
|
|
8
8
|
import Post from './Post.js';
|
|
9
|
+
import axios from 'axios';
|
|
9
10
|
export default class Release extends Model {
|
|
10
11
|
static tableName = 'releases';
|
|
11
12
|
static idColumn = 'id';
|
|
@@ -47,12 +48,19 @@ export default class Release extends Model {
|
|
|
47
48
|
const program = await anchor.Program.at(process.env.NINA_PROGRAM_ID, provider);
|
|
48
49
|
const metaplex = new Metaplex(connection);
|
|
49
50
|
const releaseAccount = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed');
|
|
50
|
-
|
|
51
|
+
let metadataAccount = (await metaplex.nfts().findAllByMintList({ mints: [releaseAccount.releaseMint] }, { commitment: 'confirmed' }))[0];
|
|
52
|
+
let json;
|
|
53
|
+
try {
|
|
54
|
+
json = await axios.get(metadataAccount.uri);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
json = await axios.get(metadataAccount.uri.replace('arweave.net', 'ar-io.net'));
|
|
58
|
+
}
|
|
51
59
|
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
52
60
|
release = await this.createRelease({
|
|
53
61
|
publicKey,
|
|
54
62
|
mint: releaseAccount.releaseMint.toBase58(),
|
|
55
|
-
metadata:
|
|
63
|
+
metadata: json,
|
|
56
64
|
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
57
65
|
publisherId: publisher.id,
|
|
58
66
|
releaseAccount
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nina-protocol/nina-db",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "src/index.js",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
24
24
|
"@babel/preset-es2015": "^7.0.0-beta.53",
|
|
25
|
-
"@metaplex-foundation/js": "^0.
|
|
25
|
+
"@metaplex-foundation/js": "^0.18.1",
|
|
26
26
|
"@project-serum/anchor": "^0.25.0",
|
|
27
27
|
"axios": "^0.27.2",
|
|
28
28
|
"knex": "^2.2.0",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"twitter-api-v2": "^1.12.9"
|
|
33
33
|
},
|
|
34
34
|
"resolutions": {
|
|
35
|
-
"@metaplex-foundation/mpl-candy-machine": "
|
|
35
|
+
"@metaplex-foundation/mpl-candy-machine": "5.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@babel/core": "^7.20.12",
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import Models from './models/index.js'
|
|
|
5
5
|
import knexConfig from './knexfile.js'
|
|
6
6
|
|
|
7
7
|
export const initDb = async (config) => {
|
|
8
|
-
const db = Knex(config)
|
|
8
|
+
const db = Knex(config.development)
|
|
9
9
|
await db.raw(`SELECT 'CREATE DATABASE ${process.env.POSTGRES_DATABASE}'
|
|
10
10
|
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${process.env.POSTGRES_DATABASE}')`
|
|
11
11
|
)
|
package/src/models/Hub.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
1
|
import { Model } from 'objection';
|
|
3
|
-
import { stripHtmlIfNeeded
|
|
2
|
+
import { stripHtmlIfNeeded } from '../utils/index.js';
|
|
4
3
|
import Account from './Account.js';
|
|
5
4
|
import Release from './Release.js';
|
|
6
5
|
import Post from './Post.js';
|
|
@@ -34,151 +33,6 @@ export default class Hub extends Model {
|
|
|
34
33
|
|
|
35
34
|
stripHtmlIfNeeded(this.data, 'description');
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
static async updateHub(hub, hubAccount, hubContents, hubReleases, hubCollaborators, hubPosts) {
|
|
39
|
-
if (typeof hubAccount.account.uri !== 'string') {
|
|
40
|
-
hubAccount.account.uri = decode(hubAccount.account.uri)
|
|
41
|
-
}
|
|
42
|
-
if (!hub.dataUri || hub.dataUri !== hubAccount.account.uri) {
|
|
43
|
-
const data = (await axios.get(hubAccount.account.uri)).data;
|
|
44
|
-
await hub.$query().patch({
|
|
45
|
-
data,
|
|
46
|
-
dataUri: hubAccount.account.uri
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Update Hub Releases
|
|
51
|
-
const hubReleasesForHubOnChain = hubReleases.filter(x => x.account.hub.toBase58() === hub.publicKey);
|
|
52
|
-
const hubReleasesForHubDb = (await Hub.relatedQuery('releases').for(hub)).map(x => x.publicKey);
|
|
53
|
-
const newHubReleasesForHub = hubReleasesForHubOnChain.filter(x => !hubReleasesForHubDb.includes(x.account.release.toBase58()));
|
|
54
|
-
|
|
55
|
-
for await (let hubRelease of hubReleasesForHubOnChain) {
|
|
56
|
-
try {
|
|
57
|
-
if (hubReleasesForHubDb.includes(hubRelease.account.release.toBase58())) {
|
|
58
|
-
const hubContent = hubContents.filter(x => x.account.child.toBase58() === hubRelease.publicKey.toBase58())[0]
|
|
59
|
-
const release = await Release.query().findOne({publicKey: hubRelease.account.release.toBase58()});
|
|
60
|
-
if (release) {
|
|
61
|
-
await Hub.relatedQuery('releases').for(hub.id).patch({
|
|
62
|
-
visible: hubContent.account.visible,
|
|
63
|
-
}).where( {id: release.id });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
} catch (err) {
|
|
67
|
-
console.log(err);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
for await (let hubRelease of newHubReleasesForHub) {
|
|
71
|
-
try {
|
|
72
|
-
const hubContent = hubContents.filter(x => x.account.child.toBase58() === hubRelease.publicKey.toBase58())[0]
|
|
73
|
-
const release = await Release.query().findOne({publicKey: hubRelease.account.release.toBase58()});
|
|
74
|
-
if (release) {
|
|
75
|
-
await Hub.relatedQuery('releases').for(hub.id).relate({
|
|
76
|
-
id: release.id,
|
|
77
|
-
hubReleasePublicKey: hubRelease.publicKey.toBase58(),
|
|
78
|
-
visible: hubContent.account.visible,
|
|
79
|
-
});
|
|
80
|
-
if (hubContent.account.publishedThroughHub) {
|
|
81
|
-
await release.$query().patch({hubId: hub.id});
|
|
82
|
-
}
|
|
83
|
-
console.log('Related Release to Hub:', release.publicKey, hub.publicKey);
|
|
84
|
-
}
|
|
85
|
-
} catch (err) {
|
|
86
|
-
console.log(err);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Update Hub Collaborators
|
|
91
|
-
const hubCollaboratorsForHubOnChain = hubCollaborators.filter(x => x.account.hub.toBase58() === hub.publicKey);
|
|
92
|
-
const hubCollaboratorsForHubDb = (await Hub.relatedQuery('collaborators').for(hub)).map(x => x.publicKey);
|
|
93
|
-
const newHubCollaboratorsForHub = hubCollaboratorsForHubOnChain.filter(x => !hubCollaboratorsForHubDb.includes(x.account.collaborator.toBase58()));
|
|
94
|
-
for await (let hubCollaborator of newHubCollaboratorsForHub) {
|
|
95
|
-
try {
|
|
96
|
-
const collaboratorRecord = await Account.findOrCreate(hubCollaborator.account.collaborator.toBase58());
|
|
97
|
-
if (collaboratorRecord) {
|
|
98
|
-
await Hub.relatedQuery('collaborators').for(hub.id).relate({
|
|
99
|
-
id: collaboratorRecord.id,
|
|
100
|
-
hubCollaboratorPublicKey: hubCollaborator.publicKey.toBase58(),
|
|
101
|
-
})
|
|
102
|
-
console.log('Related Collaborator to Hub:', collaboratorRecord.publicKey, hub.publicKey);
|
|
103
|
-
}
|
|
104
|
-
} catch (err) {
|
|
105
|
-
console.log(err);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const removedCollaborators = hubCollaboratorsForHubDb.filter(x => !hubCollaboratorsForHubOnChain.map(x => x.account.collaborator.toBase58()).includes(x));
|
|
110
|
-
for await (let removedCollaborator of removedCollaborators) {
|
|
111
|
-
try {
|
|
112
|
-
const collaboratorRecord = await Account.query().findOne({publicKey: removedCollaborator});
|
|
113
|
-
if (collaboratorRecord) {
|
|
114
|
-
await Hub.relatedQuery('collaborators').for(hub.id).unrelate().where('accountId', collaboratorRecord.id);
|
|
115
|
-
console.log('Removed Collaborator from Hub:', collaboratorRecord.publicKey, hub.publicKey);
|
|
116
|
-
}
|
|
117
|
-
} catch (err) {
|
|
118
|
-
console.log(err);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
//Update HubPosts
|
|
123
|
-
const hubPostsForHubOnChain = hubPosts.filter(x => x.account.hub.toBase58() === hub.publicKey);
|
|
124
|
-
const hubPostsForHubDb = (await Hub.relatedQuery('posts').for(hub)).map(x => x.publicKey);
|
|
125
|
-
const newHubPostsForHub = hubPostsForHubOnChain.filter(x => !hubPostsForHubDb.includes(x.account.post.toBase58()));
|
|
126
|
-
|
|
127
|
-
for await (let hubPost of hubPostsForHubOnChain) {
|
|
128
|
-
try {
|
|
129
|
-
if (hubPostsForHubDb.includes(hubPost.account.post.toBase58())) {
|
|
130
|
-
const hubContent = hubContents.filter(x => x.account.child.toBase58() === hubPost.publicKey.toBase58())[0]
|
|
131
|
-
if (!hubContent.account.visible) {
|
|
132
|
-
const post = await Post.query().findOne({publicKey: hubPost.account.post.toBase58()});
|
|
133
|
-
if (post) {
|
|
134
|
-
await Post.relatedQuery('releases').for(post.id).unrelate().where('hubId', hub.id);
|
|
135
|
-
console.log('Deleted Post:', hubPost.publicKey);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
} catch (err) {
|
|
140
|
-
console.log(err);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
for await (let hubPost of newHubPostsForHub) {
|
|
145
|
-
try {
|
|
146
|
-
const hubContent = hubContents.filter(x => x.account.child.toBase58() === hubPost.publicKey.toBase58())[0]
|
|
147
|
-
const post = await Post.query().findOne({publicKey: hubPost.account.post.toBase58()});
|
|
148
|
-
if (hubContent.account.visible) {
|
|
149
|
-
if (post) {
|
|
150
|
-
await Hub.relatedQuery('posts').for(hub.id).relate({
|
|
151
|
-
id: post.id,
|
|
152
|
-
hubPostPublicKey: hubPost.publicKey.toBase58(),
|
|
153
|
-
});
|
|
154
|
-
if (hubContent.account.publishedThroughHub) {
|
|
155
|
-
await post.$query().patch({hubId: hub.id});
|
|
156
|
-
}
|
|
157
|
-
console.log('Related Post to Hub:', post.publicKey, hub.publicKey);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (hubPost.account.referenceContent) {
|
|
161
|
-
const release = await Release.query().findOne({publicKey: hubPost.account.referenceContent.toBase58()});
|
|
162
|
-
if (release) {
|
|
163
|
-
const relatedRelease = await Post.relatedQuery('releases').for(post.id).where('releaseId', release.id).first();
|
|
164
|
-
if (!relatedRelease) {
|
|
165
|
-
await Post.relatedQuery('releases').for(post.id).relate(release.id);
|
|
166
|
-
console.log('Related Release to Post:', release.publicKey, post.publicKey);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
} else if (post) {
|
|
171
|
-
if (hubContent.account.publishedThroughHub) {
|
|
172
|
-
await Post.query().deleteById(post.id);
|
|
173
|
-
console.log('deleted Post:', post.publicKey);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
} catch (err) {
|
|
178
|
-
console.log(err);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
36
|
|
|
183
37
|
static relationMappings = () => ({
|
|
184
38
|
authority: {
|
package/src/models/Release.js
CHANGED
|
@@ -6,6 +6,7 @@ import Account from './Account.js';
|
|
|
6
6
|
import Exchange from './Exchange.js';
|
|
7
7
|
import Hub from './Hub.js';
|
|
8
8
|
import Post from './Post.js';
|
|
9
|
+
import axios from 'axios';
|
|
9
10
|
|
|
10
11
|
export default class Release extends Model {
|
|
11
12
|
static tableName = 'releases';
|
|
@@ -55,13 +56,19 @@ export default class Release extends Model {
|
|
|
55
56
|
const metaplex = new Metaplex(connection);
|
|
56
57
|
|
|
57
58
|
const releaseAccount = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed')
|
|
58
|
-
|
|
59
|
-
let
|
|
59
|
+
let metadataAccount = (await metaplex.nfts().findAllByMintList({mints: [releaseAccount.releaseMint]}, { commitment: 'confirmed' }))[0];
|
|
60
|
+
let json
|
|
61
|
+
try {
|
|
62
|
+
json = await axios.get(metadataAccount.uri)
|
|
63
|
+
} catch (error) {
|
|
64
|
+
json = await axios.get(metadataAccount.uri.replace('arweave.net', 'ar-io.net'))
|
|
65
|
+
}
|
|
60
66
|
|
|
67
|
+
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
61
68
|
release = await this.createRelease({
|
|
62
69
|
publicKey,
|
|
63
70
|
mint: releaseAccount.releaseMint.toBase58(),
|
|
64
|
-
metadata:
|
|
71
|
+
metadata: json,
|
|
65
72
|
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
66
73
|
publisherId: publisher.id,
|
|
67
74
|
releaseAccount
|