mediawiki-file-url 0.1.0 → 0.2.0

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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/index.js +3 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -15,8 +15,8 @@ import {
15
15
  mwWithBaseUrl,
16
16
  } from "mediawiki-file-url";
17
17
 
18
- // From a plain filename (default base URL is set to the TDS Wiki images root)
19
- const url1 = mwFileUrl("WarlockLevel1.png");
18
+ // From a plain filename (default base URL is set to Wikimedia Commons uploads root)
19
+ const url1 = mwFileUrl("Tesla_circa_1890.jpeg");
20
20
 
21
21
  // Set a module-wide default base URL once (used when you omit baseUrl)
22
22
  mwSetBaseUrl("https://wiki.archlinux.org/images");
package/index.js CHANGED
@@ -143,8 +143,7 @@ function md5(message) {
143
143
  * Default base URL used by mwFileUrl/mwWikiFileUrl when no baseUrl argument is provided.
144
144
  * This can be changed at runtime via mwSetBaseUrl().
145
145
  */
146
- const DEFAULT_BASE_URL =
147
- "https://static.wikia.nocookie.net/tower-defense-sim/images";
146
+ const DEFAULT_BASE_URL = "https://upload.wikimedia.org/wikipedia/commons/";
148
147
  let defaultBaseUrl = DEFAULT_BASE_URL;
149
148
 
150
149
  /**
@@ -190,7 +189,7 @@ export function mwFileUrl(filename, baseUrl) {
190
189
  const normalizedFilename = filename.replace(/ /g, "_");
191
190
 
192
191
  // Yada yada give me the md5
193
- const md5Hash = md5(normalizedFilename);
192
+ const md5Hash = md5(unescape(encodeURIComponent(normalizedFilename)));
194
193
  const firstChar = md5Hash.charAt(0);
195
194
  const firstTwoChars = md5Hash.substring(0, 2);
196
195
  const cleanBaseUrl = effectiveBaseUrl.endsWith("/")
@@ -198,7 +197,7 @@ export function mwFileUrl(filename, baseUrl) {
198
197
  : effectiveBaseUrl;
199
198
 
200
199
  // baseUrl/a/ab/Filename.png
201
- const finalUrl = `${cleanBaseUrl}/${firstChar}/${firstTwoChars}/${encodeURIComponent(normalizedFilename)}`;
200
+ const finalUrl = `${cleanBaseUrl}/${firstChar}/${firstTwoChars}/${normalizedFilename}`;
202
201
 
203
202
  return finalUrl;
204
203
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mediawiki-file-url",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Convert MediaWiki filenames into hashed upload URLs",
5
5
  "main": "index.js",
6
6
  "type": "module",