aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/activitypub.ts14
-rw-r--r--server/helpers/requests.ts12
2 files changed, 18 insertions, 8 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts
index 4bf6e387d..bcbd9be59 100644
--- a/server/helpers/activitypub.ts
+++ b/server/helpers/activitypub.ts
@@ -57,16 +57,16 @@ function activityPubContextify <T> (data: T) {
57} 57}
58 58
59type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>> 59type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>>
60async function activityPubCollectionPagination (url: string, handler: ActivityPubCollectionPaginationHandler, page?: any) { 60async function activityPubCollectionPagination (baseUrl: string, handler: ActivityPubCollectionPaginationHandler, page?: any) {
61 if (!page || !validator.isInt(page)) { 61 if (!page || !validator.isInt(page)) {
62 // We just display the first page URL, we only need the total items 62 // We just display the first page URL, we only need the total items
63 const result = await handler(0, 1) 63 const result = await handler(0, 1)
64 64
65 return { 65 return {
66 id: url, 66 id: baseUrl,
67 type: 'OrderedCollection', 67 type: 'OrderedCollection',
68 totalItems: result.total, 68 totalItems: result.total,
69 first: url + '?page=1' 69 first: baseUrl + '?page=1'
70 } 70 }
71 } 71 }
72 72
@@ -81,19 +81,19 @@ async function activityPubCollectionPagination (url: string, handler: ActivityPu
81 81
82 // There are more results 82 // There are more results
83 if (result.total > page * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) { 83 if (result.total > page * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) {
84 next = url + '?page=' + (page + 1) 84 next = baseUrl + '?page=' + (page + 1)
85 } 85 }
86 86
87 if (page > 1) { 87 if (page > 1) {
88 prev = url + '?page=' + (page - 1) 88 prev = baseUrl + '?page=' + (page - 1)
89 } 89 }
90 90
91 return { 91 return {
92 id: url + '?page=' + page, 92 id: baseUrl + '?page=' + page,
93 type: 'OrderedCollectionPage', 93 type: 'OrderedCollectionPage',
94 prev, 94 prev,
95 next, 95 next,
96 partOf: url, 96 partOf: baseUrl,
97 orderedItems: result.data, 97 orderedItems: result.data,
98 totalItems: result.total 98 totalItems: result.total
99 } 99 }
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index 51facc9e0..805930a9f 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -2,6 +2,7 @@ import * as Bluebird from 'bluebird'
2import { createWriteStream } from 'fs-extra' 2import { createWriteStream } from 'fs-extra'
3import * as request from 'request' 3import * as request from 'request'
4import { ACTIVITY_PUB } from '../initializers' 4import { ACTIVITY_PUB } from '../initializers'
5import { processImage } from './image-utils'
5 6
6function doRequest <T> ( 7function doRequest <T> (
7 requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean } 8 requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }
@@ -27,9 +28,18 @@ function doRequestAndSaveToFile (requestOptions: request.CoreOptions & request.U
27 }) 28 })
28} 29}
29 30
31async function downloadImage (url: string, destPath: string, size: { width: number, height: number }) {
32 const tmpPath = destPath + '.tmp'
33
34 await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath)
35
36 await processImage({ path: tmpPath }, destPath, size)
37}
38
30// --------------------------------------------------------------------------- 39// ---------------------------------------------------------------------------
31 40
32export { 41export {
33 doRequest, 42 doRequest,
34 doRequestAndSaveToFile 43 doRequestAndSaveToFile,
44 downloadImage
35} 45}