@nina-protocol/nina-db 0.0.24 → 0.0.26
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/knexfile.js +1 -0
- package/dist/models/Account.js +2 -1
- package/dist/models/Exchange.js +2 -1
- package/dist/models/Hub.js +2 -1
- package/dist/models/Release.js +4 -2
- package/dist/models/Verification.js +2 -1
- package/dist/utils/index.js +9 -1
- package/package.json +1 -1
- package/src/knexfile.js +1 -0
- package/src/models/Release.js +2 -1
- package/src/utils/index.js +9 -2
- package/src/node_modules/@nina-protocol/nina-db/dist/migrations/20230306215736_add_hub_updated_at.js +0 -15
- package/yarn-error.log +0 -6817
package/dist/knexfile.js
CHANGED
package/dist/models/Account.js
CHANGED
|
@@ -4,7 +4,7 @@ import Hub from './Hub.js';
|
|
|
4
4
|
import Post from './Post.js';
|
|
5
5
|
import Release from './Release.js';
|
|
6
6
|
import Verification from './Verification.js';
|
|
7
|
-
|
|
7
|
+
class Account extends Model {
|
|
8
8
|
static tableName = 'accounts';
|
|
9
9
|
static idColumn = 'id';
|
|
10
10
|
static jsonSchema = {
|
|
@@ -113,3 +113,4 @@ export default class Account extends Model {
|
|
|
113
113
|
},
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
+
export default Account;
|
package/dist/models/Exchange.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Model } from 'objection';
|
|
2
2
|
import Account from './Account.js';
|
|
3
3
|
import Release from './Release.js';
|
|
4
|
-
|
|
4
|
+
class Exchange extends Model {
|
|
5
5
|
static tableName = 'exchanges';
|
|
6
6
|
static idColum = 'id';
|
|
7
7
|
static jsonSchema = {
|
|
@@ -60,3 +60,4 @@ export default class Exchange extends Model {
|
|
|
60
60
|
},
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
+
export default Exchange;
|
package/dist/models/Hub.js
CHANGED
|
@@ -3,7 +3,7 @@ import { stripHtmlIfNeeded } from '../utils/index.js';
|
|
|
3
3
|
import Account from './Account.js';
|
|
4
4
|
import Release from './Release.js';
|
|
5
5
|
import Post from './Post.js';
|
|
6
|
-
|
|
6
|
+
class Hub extends Model {
|
|
7
7
|
static get tableName() {
|
|
8
8
|
return 'hubs';
|
|
9
9
|
}
|
|
@@ -81,3 +81,4 @@ export default class Hub extends Model {
|
|
|
81
81
|
},
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
+
export default Hub;
|
package/dist/models/Release.js
CHANGED
|
@@ -7,7 +7,7 @@ import Exchange from './Exchange.js';
|
|
|
7
7
|
import Hub from './Hub.js';
|
|
8
8
|
import Post from './Post.js';
|
|
9
9
|
import axios from 'axios';
|
|
10
|
-
|
|
10
|
+
class Release extends Model {
|
|
11
11
|
static tableName = 'releases';
|
|
12
12
|
static idColumn = 'id';
|
|
13
13
|
static jsonSchema = {
|
|
@@ -76,7 +76,7 @@ export default class Release extends Model {
|
|
|
76
76
|
publisherId,
|
|
77
77
|
});
|
|
78
78
|
await this.processRevenueShares(releaseAccount, release);
|
|
79
|
-
tweetNewRelease(metadata);
|
|
79
|
+
tweetNewRelease(metadata, publisherId);
|
|
80
80
|
return release;
|
|
81
81
|
};
|
|
82
82
|
static processRevenueShares = async (releaseData, releaseRecord) => {
|
|
@@ -101,6 +101,7 @@ export default class Release extends Model {
|
|
|
101
101
|
const publishedThroughHub = await this.$relatedQuery('publishedThroughHub');
|
|
102
102
|
if (publishedThroughHub) {
|
|
103
103
|
this.publishedThroughHub = publishedThroughHub.publicKey;
|
|
104
|
+
this.hub = publishedThroughHub;
|
|
104
105
|
}
|
|
105
106
|
this.publisher = publisher.publicKey;
|
|
106
107
|
delete this.publisherId;
|
|
@@ -184,3 +185,4 @@ export default class Release extends Model {
|
|
|
184
185
|
}
|
|
185
186
|
});
|
|
186
187
|
}
|
|
188
|
+
export default Release;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Model } from 'objection';
|
|
2
2
|
import Account from './Account.js';
|
|
3
|
-
|
|
3
|
+
class Verification extends Model {
|
|
4
4
|
static get tableName() {
|
|
5
5
|
return 'verifications';
|
|
6
6
|
}
|
|
@@ -48,3 +48,4 @@ export default class Verification extends Model {
|
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
+
export default Verification;
|
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import striptags from 'striptags';
|
|
2
2
|
import { TwitterApi } from 'twitter-api-v2';
|
|
3
|
+
import Account from '../models/Account.js';
|
|
3
4
|
const removeQuotesFromStartAndEndOfString = (string) => {
|
|
4
5
|
return string.substring(1, string.length - 1).substring(-1, string.length - 1);
|
|
5
6
|
};
|
|
@@ -14,7 +15,7 @@ export const stripHtmlIfNeeded = (object, value) => {
|
|
|
14
15
|
export const decode = (byteArray) => {
|
|
15
16
|
return new TextDecoder().decode(new Uint8Array(byteArray)).replaceAll(/\u0000/g, '');
|
|
16
17
|
};
|
|
17
|
-
export const tweetNewRelease = async (metadata) => {
|
|
18
|
+
export const tweetNewRelease = async (metadata, publisherId) => {
|
|
18
19
|
if (process.env.TWITTER_API_SECRET) {
|
|
19
20
|
try {
|
|
20
21
|
await new Promise(resolve => setTimeout(resolve, 60000));
|
|
@@ -25,6 +26,13 @@ export const tweetNewRelease = async (metadata) => {
|
|
|
25
26
|
accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
|
|
26
27
|
});
|
|
27
28
|
let text = (`${metadata.properties.artist} - "${metadata.properties.title}"`).substr(0, 250);
|
|
29
|
+
const publisher = await Account.query().findById(publisherId);
|
|
30
|
+
if (publisher) {
|
|
31
|
+
const twitterVerification = (await publisher.$relatedQuery('verifications').where('type', 'twitter').andWhere('active', true))[0];
|
|
32
|
+
if (twitterVerification) {
|
|
33
|
+
text = `${text} (@${twitterVerification.value})`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
28
36
|
text = `${text} ${metadata.external_url}`;
|
|
29
37
|
await client.v2.tweet(text);
|
|
30
38
|
}
|
package/package.json
CHANGED
package/src/knexfile.js
CHANGED
package/src/models/Release.js
CHANGED
|
@@ -84,7 +84,7 @@ export default class Release extends Model {
|
|
|
84
84
|
publisherId,
|
|
85
85
|
})
|
|
86
86
|
await this.processRevenueShares(releaseAccount, release);
|
|
87
|
-
tweetNewRelease(metadata);
|
|
87
|
+
tweetNewRelease(metadata, publisherId);
|
|
88
88
|
return release;
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -110,6 +110,7 @@ export default class Release extends Model {
|
|
|
110
110
|
const publishedThroughHub = await this.$relatedQuery('publishedThroughHub');
|
|
111
111
|
if (publishedThroughHub) {
|
|
112
112
|
this.publishedThroughHub = publishedThroughHub.publicKey;
|
|
113
|
+
this.hub = publishedThroughHub;
|
|
113
114
|
}
|
|
114
115
|
this.publisher = publisher.publicKey;
|
|
115
116
|
delete this.publisherId
|
package/src/utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import striptags from 'striptags';
|
|
2
2
|
import { TwitterApi } from 'twitter-api-v2';
|
|
3
|
+
import Account from '../models/Account.js';
|
|
3
4
|
|
|
4
5
|
const removeQuotesFromStartAndEndOfString = (string) => {
|
|
5
6
|
return string.substring(1, string.length - 1).substring(-1, string.length - 1);
|
|
@@ -18,7 +19,7 @@ export const decode = (byteArray) => {
|
|
|
18
19
|
return new TextDecoder().decode(new Uint8Array(byteArray)).replaceAll(/\u0000/g, '');
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export const tweetNewRelease = async (metadata) => {
|
|
22
|
+
export const tweetNewRelease = async (metadata, publisherId) => {
|
|
22
23
|
if (process.env.TWITTER_API_SECRET) {
|
|
23
24
|
try {
|
|
24
25
|
await new Promise(resolve => setTimeout(resolve, 60000))
|
|
@@ -28,8 +29,14 @@ export const tweetNewRelease = async (metadata) => {
|
|
|
28
29
|
accessToken: process.env.TWITTER_ACCESS_TOKEN,
|
|
29
30
|
accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
|
|
30
31
|
});
|
|
31
|
-
|
|
32
32
|
let text = (`${metadata.properties.artist} - "${metadata.properties.title}"`).substr(0, 250)
|
|
33
|
+
const publisher = await Account.query().findById(publisherId);
|
|
34
|
+
if (publisher) {
|
|
35
|
+
const twitterVerification = (await publisher.$relatedQuery('verifications').where('type', 'twitter').andWhere('active', true))[0]
|
|
36
|
+
if (twitterVerification) {
|
|
37
|
+
text = `${text} (@${twitterVerification.value})`
|
|
38
|
+
}
|
|
39
|
+
}
|
|
33
40
|
text = `${text} ${metadata.external_url}`
|
|
34
41
|
await client.v2.tweet(text);
|
|
35
42
|
} catch (error) {
|