File tree Expand file tree Collapse file tree 3 files changed +16
-36
lines changed
packages/syndicator-mastodon Expand file tree Collapse file tree 3 files changed +16
-36
lines changed Original file line number Diff line number Diff line change @@ -44,8 +44,8 @@ When sharing content to Mastodon using this syndicator, any post visibility sett
44
44
| Option | Type | Description |
45
45
| :----------------- | :-------- | :------------------------------------------------------------------------------------------------------------ |
46
46
| ` accessToken ` | ` string ` | Your Mastodon access token. _ Required_ , defaults to ` process.env.MASTODON_ACCESS_TOKEN ` . |
47
- | ` url ` | ` string ` | Your Mastodon server, i.e. ` https://mastodon.social ` . _ Required_ . |
48
47
| ` user ` | ` string ` | Your Mastodon username (without the ` @ ` ). _ Required_ . |
48
+ | ` url ` | ` string ` | Your Mastodon server. _ Optional_ , defaults to ` https://mastodon.social ` . |
49
49
| ` characterLimit ` | ` number ` | Maximum number of characters before a post is truncated. _ Optional_ , defaults to ` 500 ` . |
50
50
| ` checked ` | ` boolean ` | Tell a Micropub client whether this syndicator should be enabled by default. _ Optional_ , defaults to ` false ` . |
51
51
| ` includePermalink ` | ` boolean ` | Always include a link to the original post. _ Optional_ , defaults to ` false ` . |
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { mastodon } from "./lib/mastodon.js";
7
7
8
8
const defaults = {
9
9
accessToken : process . env . MASTODON_ACCESS_TOKEN ,
10
+ url : "https://mastodon.social" ,
10
11
characterLimit : 500 ,
11
12
checked : false ,
12
13
includePermalink : false ,
@@ -28,54 +29,42 @@ export default class MastodonSyndicator {
28
29
}
29
30
30
31
get #url( ) {
31
- return this . options ?. url ? new URL ( this . options . url ) : false ;
32
+ return new URL ( this . options . url ) ;
32
33
}
33
34
34
35
get #user( ) {
35
- return this . options ?. user
36
- ? `@${ this . options . user . replace ( "@" , "" ) } `
37
- : false ;
36
+ return this . options ?. user ? `@${ this . options . user . replace ( "@" , "" ) } ` : "" ;
38
37
}
39
38
40
39
get environment ( ) {
41
40
return [ "MASTODON_ACCESS_TOKEN" ] ;
42
41
}
43
42
44
43
get info ( ) {
45
- const service = {
46
- name : "Mastodon" ,
47
- photo : "/assets/@indiekit-syndicator-mastodon/icon.svg" ,
48
- } ;
49
44
const user = this . #user;
50
45
const url = this . #url;
51
-
52
- if ( ! url ) {
53
- return {
54
- error : "Server URL required" ,
55
- service,
56
- } ;
57
- }
58
-
59
- if ( ! user ) {
60
- return {
61
- error : "User name required" ,
62
- service,
63
- } ;
64
- }
65
-
66
46
const uid = `${ url . protocol } //${ path . join ( url . hostname , user ) } ` ;
67
- service . url = url . href ;
68
47
69
- return {
48
+ const info = {
70
49
checked : this . options . checked ,
71
50
name : `${ user } @${ url . hostname } ` ,
72
51
uid,
73
- service,
52
+ service : {
53
+ name : "Mastodon" ,
54
+ photo : "/assets/@indiekit-syndicator-mastodon/icon.svg" ,
55
+ url : url . href ,
56
+ } ,
74
57
user : {
75
58
name : user ,
76
59
url : uid ,
77
60
} ,
78
61
} ;
62
+
63
+ if ( ! user ) {
64
+ info . error = "User name required" ;
65
+ }
66
+
67
+ return info ;
79
68
}
80
69
81
70
get prompts ( ) {
Original file line number Diff line number Diff line change @@ -36,15 +36,6 @@ describe("syndicator-mastodon", () => {
36
36
assert . ok ( mastodon . info . service ) ;
37
37
} ) ;
38
38
39
- it ( "Returns error information if no server URL provided" , async ( ) => {
40
- const result = new MastodonSyndicator ( {
41
- accessToken : "token" ,
42
- user : "username" ,
43
- } ) ;
44
-
45
- assert . equal ( result . info . error , "Server URL required" ) ;
46
- } ) ;
47
-
48
39
it ( "Returns error information if no username provided" , ( ) => {
49
40
const result = new MastodonSyndicator ( {
50
41
accessToken : "token" ,
You can’t perform that action at this time.
0 commit comments