|
3 | 3 | * Released under the GNU General Public License v3.0 |
4 | 4 | */ |
5 | 5 |
|
6 | | -const version = "4.60.0"; |
| 6 | +const version = "4.60.1"; |
7 | 7 | const defaultConfig = { |
8 | 8 | enabled: false, |
9 | 9 | enabled_on_views: [], |
@@ -47,6 +47,7 @@ const defaultConfig = { |
47 | 47 | image_url: "https://picsum.photos/${width}/${height}?random=${timestamp}", |
48 | 48 | image_url_entity: "", |
49 | 49 | force_load_media_with_fetch: false, |
| 50 | + stream_load_media: false, |
50 | 51 | media_entity_load_unchanged: true, |
51 | 52 | iframe_load_unchanged: false, |
52 | 53 | iframe_interaction: false, |
@@ -2952,30 +2953,46 @@ function initWallpanel() { |
2952 | 2953 | elem.onerror = onError; |
2953 | 2954 | }); |
2954 | 2955 | if (useFetch) { |
2955 | | - fetch(url, { headers: headers }) |
2956 | | - .then((response) => { |
2957 | | - const reader = response.body.getReader(); |
2958 | | - return new ReadableStream({ |
2959 | | - start(controller) { |
2960 | | - return pump(); |
2961 | | - function pump() { |
2962 | | - return reader.read().then(({ done, value }) => { |
2963 | | - // When no more data needs to be consumed, close the stream |
2964 | | - if (done) { |
2965 | | - controller.close(); |
2966 | | - return; |
2967 | | - } |
2968 | | - // Enqueue the next data chunk into our target stream |
2969 | | - controller.enqueue(value); |
2970 | | - return pump(); |
2971 | | - }); |
| 2956 | + if (config.stream_load_media) { |
| 2957 | + fetch(url, { headers: headers }) |
| 2958 | + .then((response) => { |
| 2959 | + const reader = response.body.getReader(); |
| 2960 | + return new ReadableStream({ |
| 2961 | + start(controller) { |
| 2962 | + return pump(); |
| 2963 | + function pump() { |
| 2964 | + return reader.read().then(({ done, value }) => { |
| 2965 | + // When no more data needs to be consumed, close the stream |
| 2966 | + if (done) { |
| 2967 | + controller.close(); |
| 2968 | + return; |
| 2969 | + } |
| 2970 | + // Enqueue the next data chunk into our target stream |
| 2971 | + controller.enqueue(value); |
| 2972 | + return pump(); |
| 2973 | + }); |
| 2974 | + } |
2972 | 2975 | } |
2973 | | - } |
2974 | | - }); |
2975 | | - }) |
2976 | | - .then((stream) => new Response(stream)) |
2977 | | - .then((response) => response.blob()) |
2978 | | - .then((blob) => (elem.src = URL.createObjectURL(blob))); |
| 2976 | + }); |
| 2977 | + }) |
| 2978 | + .then((stream) => new Response(stream)) |
| 2979 | + .then((response) => response.blob()) |
| 2980 | + .then((blob) => (elem.src = URL.createObjectURL(blob))); |
| 2981 | + } else { |
| 2982 | + headers = headers || {}; |
| 2983 | + const response = await fetch(url, { headers: headers }); |
| 2984 | + logger.debug("Got respone", response); |
| 2985 | + if (!response.ok) { |
| 2986 | + throw new Error(`Failed to load ${elem.tagName} "${url}": ${response}`); |
| 2987 | + } |
| 2988 | + // The object URL created by URL.createObjectURL() must be released |
| 2989 | + // using URL.revokeObjectURL() to free the associated memory again. |
| 2990 | + if (typeof elem.src === "string" && elem.src.startsWith("blob:")) { |
| 2991 | + URL.revokeObjectURL(elem.src); |
| 2992 | + } |
| 2993 | + const blob = await response.blob(); |
| 2994 | + elem.src = URL.createObjectURL(blob); |
| 2995 | + } |
2979 | 2996 | } else { |
2980 | 2997 | elem.src = url; |
2981 | 2998 | } |
|
0 commit comments