Skip to content

Commit 6384d5f

Browse files
authored
Merge pull request #20 from fbsamples/alt_text
Alt Text
2 parents 80158c1 + bd633c0 commit 6384d5f

3 files changed

Lines changed: 37 additions & 13 deletions

File tree

src/index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const upload = multer();
2020

2121
const DEFAULT_THREADS_QUERY_LIMIT = 10;
2222

23+
const FIELD__ALT_TEXT = 'alt_text';
2324
const FIELD__ERROR_MESSAGE = 'error_message';
2425
const FIELD__FOLLOWERS_COUNT = 'followers_count';
2526
const FIELD__HIDE_STATUS = 'hide_status';
@@ -46,6 +47,7 @@ const MEDIA_TYPE__TEXT = 'TEXT';
4647
const MEDIA_TYPE__VIDEO = 'VIDEO';
4748

4849
const PARAMS__ACCESS_TOKEN = 'access_token';
50+
const PARAMS__ALT_TEXT = 'alt_text';
4951
const PARAMS__CLIENT_ID = 'client_id';
5052
const PARAMS__CONFIG = 'config';
5153
const PARAMS__FIELDS = 'fields';
@@ -298,7 +300,7 @@ app.get('/upload', loggedInUserChecker, (req, res) => {
298300
});
299301

300302
app.post('/upload', upload.array(), async (req, res) => {
301-
const { text, attachmentType, attachmentUrl, replyControl, replyToId } = req.body;
303+
const { text, attachmentType, attachmentUrl, attachmentAltText, replyControl, replyToId } = req.body;
302304
const params = {
303305
[PARAMS__TEXT]: text,
304306
[PARAMS__REPLY_CONTROL]: replyControl,
@@ -311,7 +313,7 @@ app.post('/upload', upload.array(), async (req, res) => {
311313
}
312314
// Single attachment
313315
else if (attachmentType?.length === 1) {
314-
addAttachmentFields(params, attachmentType[0], attachmentUrl[0]);
316+
addAttachmentFields(params, attachmentType[0], attachmentUrl[0], attachmentAltText[0]);
315317
}
316318
// Multiple attachments
317319
else {
@@ -321,7 +323,7 @@ app.post('/upload', upload.array(), async (req, res) => {
321323
const child = {
322324
is_carousel_item: true,
323325
};
324-
addAttachmentFields(child, type, attachmentUrl[i]);
326+
addAttachmentFields(child, type, attachmentUrl[i], attachmentAltText[i]);
325327
params.children.push(child);
326328
});
327329
}
@@ -430,7 +432,8 @@ app.get('/threads/:threadId', loggedInUserChecker, async (req, res) => {
430432
FIELD__TIMESTAMP,
431433
FIELD__IS_REPLY,
432434
FIELD__USERNAME,
433-
FIELD__REPLY_AUDIENCE
435+
FIELD__REPLY_AUDIENCE,
436+
FIELD__ALT_TEXT,
434437
].join(','),
435438
}, req.session.access_token);
436439

@@ -458,6 +461,7 @@ app.get('/threads', loggedInUserChecker, async (req, res) => {
458461
FIELD__PERMALINK,
459462
FIELD__TIMESTAMP,
460463
FIELD__REPLY_AUDIENCE,
464+
FIELD__ALT_TEXT,
461465
].join(','),
462466
limit: limit ?? DEFAULT_THREADS_QUERY_LIMIT,
463467
};
@@ -657,13 +661,15 @@ function getInsightsTotalValue(metrics, index) {
657661
* @param {string} attachmentType
658662
* @param {string} url
659663
*/
660-
function addAttachmentFields(target, attachmentType, url) {
664+
function addAttachmentFields(target, attachmentType, url, altText) {
661665
if (attachmentType === 'Image') {
662666
target.media_type = MEDIA_TYPE__IMAGE;
663667
target.image_url = url;
668+
target.alt_text = altText;
664669
} else if (attachmentType === 'Video') {
665670
target.media_type = MEDIA_TYPE__VIDEO;
666671
target.video_url = url;
672+
target.alt_text = altText;
667673
}
668674
}
669675

@@ -714,6 +720,7 @@ async function showReplies(req, res, isTopLevel) {
714720
FIELD__TIMESTAMP,
715721
FIELD__USERNAME,
716722
FIELD__HIDE_STATUS,
723+
FIELD__ALT_TEXT,
717724
].join(','),
718725
limit: limit ?? DEFAULT_THREADS_QUERY_LIMIT,
719726
};

views/thread.pug

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ block content
2020
td Media URL
2121
td
2222
a(href=media_url target='_blank') #{media_url}
23+
tr
24+
td Alt Text
25+
td #{alt_text}
2326
tr
2427
td Permalink
2528
td

views/upload.pug

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ block content
2020
justify-content: center;
2121
margin-bottom: 12px;
2222
}
23+
div.attachment-item-details {
24+
display: flex;
25+
flex-direction: column;
26+
}
27+
div.attachment-item-type-and-url {
28+
display: flex;
29+
flex-direction: row;
30+
}
2331
textarea::placeholder {
2432
text-align: center;
2533
line-height: 15px;
@@ -61,14 +69,20 @@ block content
6169

6270
script#attachment-template(type='text/template')
6371
div.attachment-item
64-
label(for='attachmentType')
65-
| Type   
66-
select(name='attachmentType[]')
67-
option(value='Image') Image
68-
option(value='Video') Video
69-
label(for='attachmentUrl')
70-
| URL   
71-
input(type='text' name='attachmentUrl[]' autocomplete='off')
72+
div.attachment-item-details
73+
div.attachment-item-type-and-url
74+
label(for='attachmentType')
75+
| Type   
76+
select(name='attachmentType[]')
77+
option(value='Image') Image
78+
option(value='Video') Video
79+
label(for='attachmentUrl')
80+
| URL   
81+
input(type='text' name='attachmentUrl[]' autocomplete='off')
82+
div.attachment-item-alt-text
83+
label(for='attachmentAltText')
84+
| Alt Text   
85+
input(type='text' name='attachmentAltText[]' value='')
7286

7387
// The parent of this node will be removed from the DOM
7488
span.delete

0 commit comments

Comments
 (0)