@nina-protocol/nina-db 0.0.92 → 0.0.93
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 +30 -0
- package/dist/knexfile.js +78 -0
- package/dist/migrations/20220815134115_initial_migration.js +211 -0
- package/dist/migrations/20220930214430_add_subscriptions.js +23 -0
- package/dist/migrations/20221010170539_add_hub_data_uri.js +15 -0
- package/dist/migrations/20221010185734_add_transactions.js +58 -0
- package/dist/migrations/20221012230835_add_verifications.js +31 -0
- package/dist/migrations/20221201221013_add_hub_releases_visible.js +15 -0
- package/dist/migrations/20221206184748_add_gate.js +29 -0
- package/dist/migrations/20230104184351_add_verification_active.js +15 -0
- package/dist/migrations/20230306215838_add_hub_updated_at.js +15 -0
- package/dist/migrations/20231011163511_add_release_slug.js +15 -0
- package/dist/migrations/20231031200532_add_profile.js +18 -0
- package/dist/migrations/20231112031914_post_version.js +15 -0
- package/dist/migrations/20231116215117_add_tags.js +40 -0
- package/dist/migrations/20240131143626_release_price.js +16 -0
- package/dist/migrations/20240304143626_fix_tags_content.js +31 -0
- package/dist/migrations/20240321155034_hide_release.js +15 -0
- package/dist/migrations/20240821155034_release_hidden_to_archived.js +18 -0
- package/dist/migrations/20241121155034_subscription_public_key_nullable.js +15 -0
- package/dist/migrations/20250120215722_add_ref_columns.js +18 -0
- package/dist/migrations/20250423215722_hubs_collaborators_permissions.js +20 -0
- package/dist/migrations/20250424215722_hubs_collaborators_added_by.js +18 -0
- package/dist/models/Account.js +122 -0
- package/dist/models/Exchange.js +62 -0
- package/dist/models/Hub.js +86 -0
- package/dist/models/Post.js +84 -0
- package/dist/models/Release.js +282 -0
- package/dist/models/Subscription.js +57 -0
- package/dist/models/Tag.js +39 -0
- package/dist/models/TagsReleases.js +17 -0
- package/dist/models/Transaction.js +148 -0
- package/dist/models/Verification.js +50 -0
- package/dist/models/index.js +21 -0
- package/dist/seeds/1_accounts_profile.js +22 -0
- package/dist/utils/index.js +45 -0
- package/package.json +1 -1
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import anchor from '@project-serum/anchor';
|
|
2
|
+
import { Metaplex } from '@metaplex-foundation/js';
|
|
3
|
+
import { Model } from 'objection';
|
|
4
|
+
import { stripHtmlIfNeeded, tweetNewRelease } from '../utils/index.js';
|
|
5
|
+
import Account from './Account.js';
|
|
6
|
+
import Exchange from './Exchange.js';
|
|
7
|
+
import Hub from './Hub.js';
|
|
8
|
+
import Post from './Post.js';
|
|
9
|
+
import Tag from './Tag.js';
|
|
10
|
+
import axios from 'axios';
|
|
11
|
+
import promiseRetry from 'promise-retry';
|
|
12
|
+
import { customAlphabet } from 'nanoid';
|
|
13
|
+
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
14
|
+
const randomStringGenerator = customAlphabet(alphabet, 12);
|
|
15
|
+
export default class Release extends Model {
|
|
16
|
+
static tableName = 'releases';
|
|
17
|
+
static idColumn = 'id';
|
|
18
|
+
static jsonSchema = {
|
|
19
|
+
type: 'object',
|
|
20
|
+
required: ['publicKey', 'mint', 'metadata', 'datetime', 'slug', 'price'],
|
|
21
|
+
properties: {
|
|
22
|
+
publicKey: { type: 'string' },
|
|
23
|
+
mint: { type: 'string' },
|
|
24
|
+
slug: { type: 'string' },
|
|
25
|
+
metadata: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
required: ['name', 'symbol', 'description', 'image', 'properties',],
|
|
28
|
+
properties: {
|
|
29
|
+
name: { type: 'string' },
|
|
30
|
+
symbol: { type: 'string' },
|
|
31
|
+
description: { type: 'string' },
|
|
32
|
+
properties: {
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {
|
|
35
|
+
artist: { type: 'string' },
|
|
36
|
+
title: { type: 'string' },
|
|
37
|
+
date: { type: 'string' },
|
|
38
|
+
files: { type: 'array' },
|
|
39
|
+
category: { type: 'string' },
|
|
40
|
+
creators: { type: 'array' },
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
price: { type: 'string' },
|
|
46
|
+
archived: { type: 'boolean' },
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
static findOrCreate = async (publicKey, hubPublicKey = null) => {
|
|
50
|
+
try {
|
|
51
|
+
let release = await Release.query().findOne({ publicKey });
|
|
52
|
+
if (release) {
|
|
53
|
+
return release;
|
|
54
|
+
}
|
|
55
|
+
const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
|
|
56
|
+
const provider = new anchor.AnchorProvider(connection, {}, { commitment: 'confirmed' });
|
|
57
|
+
const program = await anchor.Program.at(process.env.NINA_PROGRAM_ID, provider);
|
|
58
|
+
const metaplex = new Metaplex(connection);
|
|
59
|
+
let attempts = 0;
|
|
60
|
+
const releaseAccount = await promiseRetry(async (retry) => {
|
|
61
|
+
try {
|
|
62
|
+
attempts += 1;
|
|
63
|
+
const result = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed');
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.log('error fetching release account', error);
|
|
68
|
+
retry(error);
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
retries: 50,
|
|
72
|
+
minTimeout: 500,
|
|
73
|
+
maxTimeout: 1500,
|
|
74
|
+
});
|
|
75
|
+
let metadataAccount = (await metaplex.nfts().findAllByMintList({ mints: [releaseAccount.releaseMint] }, { commitment: 'confirmed' }))[0];
|
|
76
|
+
if (!metadataAccount) {
|
|
77
|
+
throw new Error('No metadata account found for release - is not a complete release');
|
|
78
|
+
}
|
|
79
|
+
let json;
|
|
80
|
+
try {
|
|
81
|
+
json = (await axios.get(metadataAccount.uri.replace('www.', '').replace('arweave.net', 'gateway.irys.xyz'))).data;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
json = (await axios.get(metadataAccount.uri.replace('gateway.irys.xyz', 'arweave.net'))).data;
|
|
85
|
+
}
|
|
86
|
+
const slug = await this.generateSlug(json);
|
|
87
|
+
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
88
|
+
release = await this.createRelease({
|
|
89
|
+
publicKey,
|
|
90
|
+
mint: releaseAccount.releaseMint.toBase58(),
|
|
91
|
+
metadata: json,
|
|
92
|
+
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
93
|
+
slug,
|
|
94
|
+
publisherId: publisher.id,
|
|
95
|
+
releaseAccount
|
|
96
|
+
});
|
|
97
|
+
if (hubPublicKey) {
|
|
98
|
+
const hub = await Hub.query().findOne({ publicKey: hubPublicKey });
|
|
99
|
+
await release.$query().patch({ hubId: hub.id });
|
|
100
|
+
await Hub.relatedQuery('releases').for(hub.id).patch({
|
|
101
|
+
visible: true,
|
|
102
|
+
}).where({ id: release.id });
|
|
103
|
+
}
|
|
104
|
+
return release;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.log('error finding or creating release: ', error);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
static createRelease = async ({ publicKey, mint, metadata, datetime, publisherId, releaseAccount }) => {
|
|
112
|
+
const slug = await this.generateSlug(metadata);
|
|
113
|
+
const price = releaseAccount.account?.price?.toNumber() || releaseAccount?.price?.toNumber() || 0;
|
|
114
|
+
const paymentMint = releaseAccount.account?.paymentMint.toBase58() || releaseAccount?.paymentMint.toBase58();
|
|
115
|
+
const release = await Release.query().insertGraph({
|
|
116
|
+
publicKey,
|
|
117
|
+
mint,
|
|
118
|
+
metadata,
|
|
119
|
+
slug,
|
|
120
|
+
datetime,
|
|
121
|
+
publisherId,
|
|
122
|
+
price: `${price}`,
|
|
123
|
+
paymentMint,
|
|
124
|
+
archived: false
|
|
125
|
+
});
|
|
126
|
+
if (metadata.properties.tags) {
|
|
127
|
+
for await (let tag of metadata.properties.tags) {
|
|
128
|
+
const tagRecord = await Tag.findOrCreate(tag);
|
|
129
|
+
await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id).onConflict(['tagId', 'releaseId']).ignore();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
await this.processRevenueShares(releaseAccount, release);
|
|
133
|
+
tweetNewRelease(metadata, publisherId, slug);
|
|
134
|
+
return release;
|
|
135
|
+
};
|
|
136
|
+
static processRevenueShares = async (releaseData, releaseRecord) => {
|
|
137
|
+
const royaltyRecipients = releaseData.account?.royaltyRecipients || releaseData.royaltyRecipients;
|
|
138
|
+
for await (let recipient of royaltyRecipients) {
|
|
139
|
+
try {
|
|
140
|
+
if (recipient.recipientAuthority.toBase58() !== "11111111111111111111111111111111") {
|
|
141
|
+
const recipientAccount = await Account.findOrCreate(recipient.recipientAuthority.toBase58());
|
|
142
|
+
const revenueShares = (await recipientAccount.$relatedQuery('revenueShares')).map(revenueShare => revenueShare.id);
|
|
143
|
+
if (!revenueShares.includes(releaseRecord.id) && recipient.percentShare.toNumber() > 0) {
|
|
144
|
+
await Account.relatedQuery('revenueShares').for(recipientAccount.id).relate(releaseRecord.id);
|
|
145
|
+
}
|
|
146
|
+
else if (revenueShares.includes(releaseRecord.id) && recipient.percentShare.toNumber() === 0) {
|
|
147
|
+
await Account.relatedQuery('revenueShares').for(recipientAccount.id).unrelate().where('id', releaseRecord.id);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
console.log('error processing royaltyRecipients: ', error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
static generateSlug = async (metadata) => {
|
|
157
|
+
let string = metadata.name;
|
|
158
|
+
if (string.length > 200) {
|
|
159
|
+
string = string.substring(0, 200);
|
|
160
|
+
}
|
|
161
|
+
const slug = string
|
|
162
|
+
.normalize('NFKD').replace(/[\u0300-\u036F]/g, '') // remove accents and convert to closest ascii equivalent
|
|
163
|
+
.toLowerCase() // convert to lowercase
|
|
164
|
+
.replace('-', '') // remove hyphens
|
|
165
|
+
.replace(/ +/g, ' ') // remove spaces
|
|
166
|
+
.replace(/ /g, '-') // replace spaces with hyphens
|
|
167
|
+
.replace(/[^a-zA-Z0-9-]/g, '-') // replace non-alphanumeric characters with hyphens
|
|
168
|
+
.replace(/-+/g, '-') // replace multiple hyphens with single hyphen
|
|
169
|
+
.replace(/-$/, ''); // remove trailing hyphens
|
|
170
|
+
const existingRelease = await Release.query().findOne({ slug });
|
|
171
|
+
if (existingRelease) {
|
|
172
|
+
return `${slug}-${randomStringGenerator()}`;
|
|
173
|
+
}
|
|
174
|
+
return slug;
|
|
175
|
+
};
|
|
176
|
+
format = async () => {
|
|
177
|
+
const publisher = await this.$relatedQuery('publisher');
|
|
178
|
+
const publishedThroughHub = await this.$relatedQuery('publishedThroughHub');
|
|
179
|
+
if (publishedThroughHub) {
|
|
180
|
+
this.publishedThroughHub = publishedThroughHub.publicKey;
|
|
181
|
+
this.hub = publishedThroughHub;
|
|
182
|
+
delete this.hub.id;
|
|
183
|
+
const authority = await this.hub.$relatedQuery('authority').select('publicKey');
|
|
184
|
+
this.hub.authority = authority.publicKey;
|
|
185
|
+
delete this.hub.authorityId;
|
|
186
|
+
}
|
|
187
|
+
await publisher.format();
|
|
188
|
+
this.publisher = publisher.publicKey;
|
|
189
|
+
this.publisherAccount = publisher;
|
|
190
|
+
delete this.publisherId;
|
|
191
|
+
delete this.hubId;
|
|
192
|
+
delete this.id;
|
|
193
|
+
stripHtmlIfNeeded(this.metadata, 'description');
|
|
194
|
+
};
|
|
195
|
+
static relationMappings = () => ({
|
|
196
|
+
publishedThroughHub: {
|
|
197
|
+
relation: Model.BelongsToOneRelation,
|
|
198
|
+
modelClass: Hub,
|
|
199
|
+
join: {
|
|
200
|
+
from: 'releases.hubId',
|
|
201
|
+
to: 'hubs.id',
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
publisher: {
|
|
205
|
+
relation: Model.HasOneRelation,
|
|
206
|
+
modelClass: Account,
|
|
207
|
+
join: {
|
|
208
|
+
from: 'releases.publisherId',
|
|
209
|
+
to: 'accounts.id',
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
collectors: {
|
|
213
|
+
relation: Model.ManyToManyRelation,
|
|
214
|
+
modelClass: Account,
|
|
215
|
+
join: {
|
|
216
|
+
from: 'releases.id',
|
|
217
|
+
through: {
|
|
218
|
+
from: 'releases_collected.releaseId',
|
|
219
|
+
to: 'releases_collected.accountId',
|
|
220
|
+
},
|
|
221
|
+
to: 'accounts.id',
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
exchanges: {
|
|
225
|
+
relation: Model.HasManyRelation,
|
|
226
|
+
modelClass: Exchange,
|
|
227
|
+
join: {
|
|
228
|
+
from: 'releases.id',
|
|
229
|
+
to: 'exchanges.releaseId',
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
hubs: {
|
|
233
|
+
relation: Model.ManyToManyRelation,
|
|
234
|
+
modelClass: Hub,
|
|
235
|
+
join: {
|
|
236
|
+
from: 'releases.id',
|
|
237
|
+
through: {
|
|
238
|
+
from: 'hubs_releases.releaseId',
|
|
239
|
+
to: 'hubs_releases.hubId',
|
|
240
|
+
extra: ['hubReleasePublicKey'],
|
|
241
|
+
},
|
|
242
|
+
to: 'hubs.id',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
posts: {
|
|
246
|
+
relation: Model.ManyToManyRelation,
|
|
247
|
+
modelClass: Post,
|
|
248
|
+
join: {
|
|
249
|
+
from: 'releases.id',
|
|
250
|
+
through: {
|
|
251
|
+
from: 'posts_releases.releaseId',
|
|
252
|
+
to: 'posts_releases.postId',
|
|
253
|
+
},
|
|
254
|
+
to: 'posts.id',
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
revenueShareRecipients: {
|
|
258
|
+
relation: Model.ManyToManyRelation,
|
|
259
|
+
modelClass: Account,
|
|
260
|
+
join: {
|
|
261
|
+
from: 'releases.id',
|
|
262
|
+
through: {
|
|
263
|
+
from: 'releases_revenue_share.releaseId',
|
|
264
|
+
to: 'releases_revenue_share.accountId',
|
|
265
|
+
},
|
|
266
|
+
to: 'accounts.id',
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
tags: {
|
|
270
|
+
relation: Model.ManyToManyRelation,
|
|
271
|
+
modelClass: Tag,
|
|
272
|
+
join: {
|
|
273
|
+
from: 'releases.id',
|
|
274
|
+
through: {
|
|
275
|
+
from: 'tags_releases.releaseId',
|
|
276
|
+
to: 'tags_releases.tagId',
|
|
277
|
+
},
|
|
278
|
+
to: 'tags.id',
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
import Account from './Account.js';
|
|
3
|
+
import Hub from './Hub.js';
|
|
4
|
+
class Subscription extends Model {
|
|
5
|
+
static get tableName() {
|
|
6
|
+
return 'subscriptions';
|
|
7
|
+
}
|
|
8
|
+
static get idColumn() {
|
|
9
|
+
return 'id';
|
|
10
|
+
}
|
|
11
|
+
static get jsonSchema() {
|
|
12
|
+
return {
|
|
13
|
+
type: 'object',
|
|
14
|
+
required: ['datetime'],
|
|
15
|
+
properties: {
|
|
16
|
+
datetime: { type: 'string' },
|
|
17
|
+
from: { type: 'string' },
|
|
18
|
+
to: { type: 'string' },
|
|
19
|
+
subscriptionType: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
enum: ['account', 'hub'],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
static async findOrCreate({ from, to, datetime, subscriptionType }) {
|
|
27
|
+
let subscription = await Subscription.query().findOne({ from, to });
|
|
28
|
+
if (subscription) {
|
|
29
|
+
return subscription;
|
|
30
|
+
}
|
|
31
|
+
subscription = await Subscription.query().insert({
|
|
32
|
+
from, to, datetime, subscriptionType
|
|
33
|
+
});
|
|
34
|
+
console.log('Inserted subscription: ', from, to);
|
|
35
|
+
return subscription;
|
|
36
|
+
}
|
|
37
|
+
async format() {
|
|
38
|
+
if (this.subscriptionType === 'account') {
|
|
39
|
+
const accountTo = await Account.query().findOne({ publicKey: this.to });
|
|
40
|
+
await accountTo.format();
|
|
41
|
+
this.to = accountTo;
|
|
42
|
+
const accountFrom = await Account.query().findOne({ publicKey: this.from });
|
|
43
|
+
await accountFrom.format();
|
|
44
|
+
this.from = accountFrom;
|
|
45
|
+
}
|
|
46
|
+
else if (this.subscriptionType === 'hub') {
|
|
47
|
+
const hub = await Hub.query().findOne({ publicKey: this.to });
|
|
48
|
+
await hub.format();
|
|
49
|
+
this.to = hub;
|
|
50
|
+
const account = await Account.query().findOne({ publicKey: this.from });
|
|
51
|
+
await account.format();
|
|
52
|
+
this.from = account;
|
|
53
|
+
}
|
|
54
|
+
delete this.id;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export default Subscription;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
import Release from './Release.js';
|
|
3
|
+
export default class Tag extends Model {
|
|
4
|
+
static tableName = 'tags';
|
|
5
|
+
static idColumn = 'id';
|
|
6
|
+
static jsonSchema = {
|
|
7
|
+
type: 'object',
|
|
8
|
+
required: ['value'],
|
|
9
|
+
properties: {
|
|
10
|
+
value: { type: 'string' },
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
static sanitizeValue = (value) => value.toLowerCase().replace('#', '').replace(',', '');
|
|
14
|
+
static findOrCreate = async (value) => {
|
|
15
|
+
const sanitizedValue = this.sanitizeValue(value);
|
|
16
|
+
let tag = await Tag.query().where('value', sanitizedValue).first();
|
|
17
|
+
if (!tag) {
|
|
18
|
+
tag = await Tag.query().insert({ value: sanitizedValue });
|
|
19
|
+
}
|
|
20
|
+
return tag;
|
|
21
|
+
};
|
|
22
|
+
format = () => {
|
|
23
|
+
delete this.id;
|
|
24
|
+
};
|
|
25
|
+
static relationMappings = () => ({
|
|
26
|
+
releases: {
|
|
27
|
+
relation: Model.ManyToManyRelation,
|
|
28
|
+
modelClass: Release,
|
|
29
|
+
join: {
|
|
30
|
+
from: 'tags.id',
|
|
31
|
+
through: {
|
|
32
|
+
from: 'tags_releases.tagId',
|
|
33
|
+
to: 'tags_releases.releaseId',
|
|
34
|
+
},
|
|
35
|
+
to: 'releases.id',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
export default class TagsRelease extends Model {
|
|
3
|
+
static tableName = 'tags_releases';
|
|
4
|
+
$beforeUpdate() {
|
|
5
|
+
this.updatedAt = new Date().toISOString();
|
|
6
|
+
}
|
|
7
|
+
static jsonSchema = {
|
|
8
|
+
type: 'object',
|
|
9
|
+
required: ['tagId', 'releaseId', 'createdAt', 'updatedAt'],
|
|
10
|
+
properties: {
|
|
11
|
+
tagId: { type: 'integer' },
|
|
12
|
+
releaseId: { type: 'integer' },
|
|
13
|
+
createdAt: { type: 'string' },
|
|
14
|
+
updatedAt: { type: 'string' },
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
import Account from './Account.js';
|
|
3
|
+
import Hub from './Hub.js';
|
|
4
|
+
import Release from './Release.js';
|
|
5
|
+
import Post from './Post.js';
|
|
6
|
+
class Transaction extends Model {
|
|
7
|
+
static get tableName() {
|
|
8
|
+
return 'transactions';
|
|
9
|
+
}
|
|
10
|
+
static get idColumn() {
|
|
11
|
+
return 'id';
|
|
12
|
+
}
|
|
13
|
+
static get jsonSchema() {
|
|
14
|
+
return {
|
|
15
|
+
type: 'object',
|
|
16
|
+
required: ['txid', 'blocktime', 'type'],
|
|
17
|
+
properties: {
|
|
18
|
+
txid: { type: 'string' },
|
|
19
|
+
blocktime: { type: 'integer' },
|
|
20
|
+
type: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
enum: [
|
|
23
|
+
'ExchangeAccept',
|
|
24
|
+
'ExchangeCancel',
|
|
25
|
+
'ExchangeInit',
|
|
26
|
+
'HubInit',
|
|
27
|
+
'HubInitWithCredit',
|
|
28
|
+
'HubAddCollaborator',
|
|
29
|
+
'HubContentToggleVisibility',
|
|
30
|
+
'HubRemoveCollaborator',
|
|
31
|
+
'HubUpdateCollaboratorPermissions',
|
|
32
|
+
'HubUpdateConfig',
|
|
33
|
+
'HubAddRelease',
|
|
34
|
+
'HubWithdraw',
|
|
35
|
+
'PostInitViaHub',
|
|
36
|
+
'PostInitViaHubWithReferenceRelease',
|
|
37
|
+
'ReleaseClaim',
|
|
38
|
+
'ReleaseCloseEdition',
|
|
39
|
+
'ReleaseInit',
|
|
40
|
+
'ReleaseInitWithCredit',
|
|
41
|
+
'ReleaseInitViaHub',
|
|
42
|
+
'ReleasePurchase',
|
|
43
|
+
'ReleasePurchaseViaHub',
|
|
44
|
+
'ReleaseRevenueShareCollectViaHub',
|
|
45
|
+
'ReleaseRevenueShareCollect',
|
|
46
|
+
'ReleaseRevenueShareTransfer',
|
|
47
|
+
'ReleaseUpdateMetadata',
|
|
48
|
+
'SubscriptionSubscribeAccount',
|
|
49
|
+
'SubscriptionSubscribeHub',
|
|
50
|
+
'SubscriptionUnsubscribe',
|
|
51
|
+
'Unknown',
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async format() {
|
|
58
|
+
const hub = await this.$relatedQuery('hub');
|
|
59
|
+
if (hub) {
|
|
60
|
+
await hub.format();
|
|
61
|
+
this.hub = hub;
|
|
62
|
+
}
|
|
63
|
+
delete this.hubId;
|
|
64
|
+
const authority = await this.$relatedQuery('authority');
|
|
65
|
+
if (authority) {
|
|
66
|
+
await authority.format();
|
|
67
|
+
this.authority = authority;
|
|
68
|
+
}
|
|
69
|
+
delete this.authorityId;
|
|
70
|
+
const release = await this.$relatedQuery('release');
|
|
71
|
+
if (release) {
|
|
72
|
+
await release.format();
|
|
73
|
+
this.release = release;
|
|
74
|
+
}
|
|
75
|
+
delete this.releaseId;
|
|
76
|
+
const post = await this.$relatedQuery('post');
|
|
77
|
+
if (post) {
|
|
78
|
+
await post.format();
|
|
79
|
+
this.post = post;
|
|
80
|
+
}
|
|
81
|
+
delete this.postId;
|
|
82
|
+
const toAccount = await this.$relatedQuery('toAccount');
|
|
83
|
+
if (toAccount) {
|
|
84
|
+
await toAccount.format();
|
|
85
|
+
this.toAccount = toAccount;
|
|
86
|
+
}
|
|
87
|
+
delete this.toAccountId;
|
|
88
|
+
const toHub = await this.$relatedQuery('toHub');
|
|
89
|
+
if (toHub) {
|
|
90
|
+
await toHub.format();
|
|
91
|
+
this.toHub = toHub;
|
|
92
|
+
}
|
|
93
|
+
delete this.toHubId;
|
|
94
|
+
this.datetime = new Date(this.blocktime * 1000).toISOString();
|
|
95
|
+
delete this.id;
|
|
96
|
+
}
|
|
97
|
+
static relationMappings = () => ({
|
|
98
|
+
authority: {
|
|
99
|
+
relation: Model.HasOneRelation,
|
|
100
|
+
modelClass: Account,
|
|
101
|
+
join: {
|
|
102
|
+
from: 'transactions.authorityId',
|
|
103
|
+
to: 'accounts.id',
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
hub: {
|
|
107
|
+
relation: Model.HasOneRelation,
|
|
108
|
+
modelClass: Hub,
|
|
109
|
+
join: {
|
|
110
|
+
from: 'transactions.hubId',
|
|
111
|
+
to: 'hubs.id',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
release: {
|
|
115
|
+
relation: Model.HasOneRelation,
|
|
116
|
+
modelClass: Release,
|
|
117
|
+
join: {
|
|
118
|
+
from: 'transactions.releaseId',
|
|
119
|
+
to: 'releases.id',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
post: {
|
|
123
|
+
relation: Model.HasOneRelation,
|
|
124
|
+
modelClass: Post,
|
|
125
|
+
join: {
|
|
126
|
+
from: 'transactions.postId',
|
|
127
|
+
to: 'posts.id',
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
toAccount: {
|
|
131
|
+
relation: Model.HasOneRelation,
|
|
132
|
+
modelClass: Account,
|
|
133
|
+
join: {
|
|
134
|
+
from: 'transactions.toAccountId',
|
|
135
|
+
to: 'accounts.id',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
toHub: {
|
|
139
|
+
relation: Model.HasOneRelation,
|
|
140
|
+
modelClass: Hub,
|
|
141
|
+
join: {
|
|
142
|
+
from: 'transactions.toHubId',
|
|
143
|
+
to: 'hubs.id',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
export default Transaction;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
import Account from './Account.js';
|
|
3
|
+
export default class Verification extends Model {
|
|
4
|
+
static get tableName() {
|
|
5
|
+
return 'verifications';
|
|
6
|
+
}
|
|
7
|
+
static get idColumn() {
|
|
8
|
+
return 'id';
|
|
9
|
+
}
|
|
10
|
+
static get jsonSchema() {
|
|
11
|
+
return {
|
|
12
|
+
type: 'object',
|
|
13
|
+
required: ['publicKey', 'type', 'value'],
|
|
14
|
+
properties: {
|
|
15
|
+
publicKey: { type: 'string' },
|
|
16
|
+
type: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
enum: [
|
|
19
|
+
'soundcloud',
|
|
20
|
+
'instagram',
|
|
21
|
+
'twitter',
|
|
22
|
+
'ethereum',
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
value: { type: 'string' },
|
|
26
|
+
displayName: { type: 'string' },
|
|
27
|
+
image: { type: 'string' },
|
|
28
|
+
description: { type: 'string' },
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async format() {
|
|
33
|
+
delete this.id;
|
|
34
|
+
const account = await this.$relatedQuery('account');
|
|
35
|
+
delete this.accountId;
|
|
36
|
+
if (account) {
|
|
37
|
+
this.account = account.publicKey;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
static relationMappings = () => ({
|
|
41
|
+
account: {
|
|
42
|
+
relation: Model.BelongsToOneRelation,
|
|
43
|
+
modelClass: Account,
|
|
44
|
+
join: {
|
|
45
|
+
from: 'verifications.accountId',
|
|
46
|
+
to: 'accounts.id',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Account from './Account.js';
|
|
2
|
+
import Exchange from './Exchange.js';
|
|
3
|
+
import Hub from './Hub.js';
|
|
4
|
+
import Post from './Post.js';
|
|
5
|
+
import Release from './Release.js';
|
|
6
|
+
import Subscription from './Subscription.js';
|
|
7
|
+
import Tag from './Tag.js';
|
|
8
|
+
import Transaction from './Transaction.js';
|
|
9
|
+
import Verification from './Verification.js';
|
|
10
|
+
const models = {
|
|
11
|
+
Account,
|
|
12
|
+
Exchange,
|
|
13
|
+
Hub,
|
|
14
|
+
Post,
|
|
15
|
+
Release,
|
|
16
|
+
Subscription,
|
|
17
|
+
Tag,
|
|
18
|
+
Transaction,
|
|
19
|
+
Verification,
|
|
20
|
+
};
|
|
21
|
+
export default models;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { Account, connectDb } from '../index.js';
|
|
4
|
+
export const seed = async () => {
|
|
5
|
+
await connectDb();
|
|
6
|
+
const accountsWithoutHandle = await Account.query().whereNull('handle');
|
|
7
|
+
for await (let account of accountsWithoutHandle) {
|
|
8
|
+
try {
|
|
9
|
+
const response = await axios.get(`${process.env.ID_SERVER_ENDPOINT}/profile/${account.publicKey}`);
|
|
10
|
+
await account.$query().patch({
|
|
11
|
+
handle: response.data.profile.handle,
|
|
12
|
+
displayName: response.data.profile.displayName,
|
|
13
|
+
image: response.data.profile.image,
|
|
14
|
+
description: response.data.profile.description,
|
|
15
|
+
});
|
|
16
|
+
console.log('Updated Account:', account.handle, account.publicKey);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.log('Error updating Account', account.publicKey, error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import striptags from 'striptags';
|
|
2
|
+
import { TwitterApi } from 'twitter-api-v2';
|
|
3
|
+
import Account from '../models/Account.js';
|
|
4
|
+
const TWEET_DELAY = 360000; // 6 minutes
|
|
5
|
+
const NINA_DOMAIN = 'https://ninaprotocol.com';
|
|
6
|
+
const removeQuotesFromStartAndEndOfString = (string) => {
|
|
7
|
+
return string.substring(1, string.length - 1).substring(-1, string.length - 1);
|
|
8
|
+
};
|
|
9
|
+
export const stripHtmlIfNeeded = (object, value) => {
|
|
10
|
+
let strippedDescription = striptags(object[value], [], ' ');
|
|
11
|
+
strippedDescription = strippedDescription.replace(' ', ' ');
|
|
12
|
+
if (strippedDescription !== object[value]) {
|
|
13
|
+
object[value + "Html"] = object[value];
|
|
14
|
+
object[value] = removeQuotesFromStartAndEndOfString(strippedDescription);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const decode = (byteArray) => {
|
|
18
|
+
return new TextDecoder().decode(new Uint8Array(byteArray)).replaceAll(/\u0000/g, '');
|
|
19
|
+
};
|
|
20
|
+
export const tweetNewRelease = async (metadata, publisherId, slug) => {
|
|
21
|
+
if (process.env.TWITTER_API_SECRET) {
|
|
22
|
+
try {
|
|
23
|
+
await new Promise(resolve => setTimeout(resolve, TWEET_DELAY));
|
|
24
|
+
const client = new TwitterApi({
|
|
25
|
+
appKey: process.env.TWITTER_API_KEY,
|
|
26
|
+
appSecret: process.env.TWITTER_API_SECRET,
|
|
27
|
+
accessToken: process.env.TWITTER_ACCESS_TOKEN,
|
|
28
|
+
accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
|
|
29
|
+
});
|
|
30
|
+
let text = (`${metadata.properties.artist ? `${metadata.properties.artist} - ` : ''}${metadata.properties.title}`).substr(0, 250);
|
|
31
|
+
const publisher = await Account.query().findById(publisherId);
|
|
32
|
+
if (publisher) {
|
|
33
|
+
const twitterVerification = (await publisher.$relatedQuery('verifications').where('type', 'twitter').andWhere('active', true))[0];
|
|
34
|
+
if (twitterVerification) {
|
|
35
|
+
text = `${text} (@${twitterVerification.value})`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
text = `${text} ${NINA_DOMAIN}/releases/${slug}`;
|
|
39
|
+
await client.v2.tweet(text);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.warn('error sending new release tweet: ', error, metadata);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|