Skip to content

Commit

Permalink
Refactor legacyDownloadInfo out from code
Browse files Browse the repository at this point in the history
  • Loading branch information
gyng committed May 21, 2019
1 parent d423db1 commit b545316
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 50 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.5.1 (Unreleased)

* Refactor `legacyDownloadInfo` out from code

# 3.5.0

* Make options page support dark mode for Firefox (#112)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "3.5.0",
"version": "3.5.1",
"default_locale": "en",

"applications": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "save-in",
"version": "3.5.0",
"version": "3.5.1",
"license": "MIT",
"scripts": {
"build": "env -u WEB_EXT_API_KEY -u WEB_EXT_API_SECRET web-ext build --overwrite-dest -i test docs yarn.lock yarn-error.log",
Expand Down
6 changes: 1 addition & 5 deletions src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ const Download = {
return null;
}

return Router.matchRules(
filenamePatterns,
state.info.legacyDownloadInfo,
state.info
);
return Router.matchRules(filenamePatterns, state.info);
},

renameAndDownload: state => {
Expand Down
6 changes: 2 additions & 4 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ const Menus = {
context: downloadType,
menuIndex,
comment,
modifiers: info.modifiers,
legacyDownloadInfo: info // wip, remove
modifiers: info.modifiers
};

// keeps track of state of the final path
Expand Down Expand Up @@ -563,8 +562,7 @@ const Menus = {
context: DOWNLOAD_TYPES.TAB,
menuIndex: null,
comment: null,
modifiers: info.modifiers,
legacyDownloadInfo: info // wip, remove
modifiers: info.modifiers
};

// keeps track of state of the final path
Expand Down
14 changes: 7 additions & 7 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ const Router = {
return rules;
},

getCaptureMatches: (rule, info, rest) => {
getCaptureMatches: (rule, info) => {
const captureDeclaration = rule.find(
d => d.type === RULE_TYPES.CAPTURE && d.name === "capture"
);
Expand All @@ -304,16 +304,16 @@ const Router = {
return null;
}

return captured.matcher(info, rest);
return captured.matcher(info);
} else {
return null;
}
},

matchRule: (rule, info, rest) => {
matchRule: (rule, info) => {
const matches = rule
.filter(m => m.type === RULE_TYPES.MATCHER)
.map(m => m.matcher(info, rest));
.map(m => m.matcher(info, info));

if (matches.some(m => !m)) {
return false;
Expand All @@ -322,7 +322,7 @@ const Router = {
let destination = rule.find(r => r.name === "into").value;

// Regex capture groups
const capturedMatches = Router.getCaptureMatches(rule, info, rest);
const capturedMatches = Router.getCaptureMatches(rule, info);

if (capturedMatches) {
for (let i = 0; i < capturedMatches.length; i += 1) {
Expand All @@ -333,9 +333,9 @@ const Router = {
return destination;
},

matchRules: (rules, info, rest) => {
matchRules: (rules, info) => {
for (let i = 0; i < rules.length; i += 1) {
const result = Router.matchRule(rules[i], info, rest);
const result = Router.matchRule(rules[i], info);
if (result) {
return result;
}
Expand Down
22 changes: 0 additions & 22 deletions test/fixtures/clickInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ const firefoxInfo = {
menuIndex: "1",
comment: "",
modifiers: [],
legacyDownloadInfo: {
menuItemId: "save-in-1--.",
editable: false,
parentMenuItemId: "save-in-_-_-root",
mediaType: "image",
linkText: "",
linkUrl: "",
srcUrl: "https://pbs.twimg.com/media/Di6uEBuVsAEYVBw.jpg:orig",
pageUrl: "https://pbs.twimg.com/media/Di6uEBuVsAEYVBw.jpg:orig",
frameUrl: "https://pbs.twimg.com/media/Di6uEBuVsAEYVBw.jpg:orig",
frameId: 0,
modifiers: []
},
naiveFilename: "Di6uEBuVsAEYVBw.jpg:orig",
filename: "Di6uEBuVsAEYVBw.jpg:orig",
initialFilename: "Di6uEBuVsAEYVBw.jpg:orig",
Expand Down Expand Up @@ -105,15 +92,6 @@ const chromeInfo = {
context: "MEDIA",
menuIndex: "1",
comment: "",
legacyDownloadInfo: {
editable: false,
frameId: 0,
mediaType: "image",
menuItemId: "save-in-1--.",
pageUrl: "https://pbs.twimg.com/media/Di6uEBuVsAEYVBw.jpg:orig",
parentMenuItemId: "save-in-_-_-root",
srcUrl: "https://pbs.twimg.com/media/Di6uEBuVsAEYVBw.jpg:orig"
},
naiveFilename: "Di6uEBuVsAEYVBw.jpg:orig",
filename: "Di6uEBuVsAEYVBw.jpg_orig",
initialFilename: "Di6uEBuVsAEYVBw.jpg:orig"
Expand Down
12 changes: 2 additions & 10 deletions test/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ describe("filename rewrite and routing", () => {

const clickInfo = fixtures.firefoxInfo;

const matched = router.matchRules(
twitterRulesFirefox,
clickInfo.legacyDownloadInfo,
clickInfo
);
const matched = router.matchRules(twitterRulesFirefox, clickInfo);

expect(matched).toBe("Di6uEBuVsAEYVBw.jpg");
});
Expand All @@ -216,11 +212,7 @@ describe("filename rewrite and routing", () => {

const clickInfo = fixtures.chromeInfo;

const matched = router.matchRules(
twitterRulesChrome,
clickInfo.legacyDownloadInfo,
clickInfo
);
const matched = router.matchRules(twitterRulesChrome, clickInfo);

expect(matched).toBe("Di6uEBuVsAEYVBw.jpg");
});
Expand Down

0 comments on commit b545316

Please sign in to comment.