Fossil SCM
/jchunk now always uses a JSON response, even for permissions problems. Doc improvements for the jchunk interface.
Commit
1fec5f4abc3b2a478ae442b0f6807038afa9e56b41358ebd885409836ef52ecf
Parent
1da4b6c7522eb19…
2 files changed
+14
-10
+10
-5
+14
-10
| --- src/fossil.diff.js | ||
| +++ src/fossil.diff.js | ||
| @@ -23,37 +23,41 @@ | ||
| 23 | 23 | window.fossil.onPageLoad(function(){ |
| 24 | 24 | const F = window.fossil, D = F.dom; |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | Uses the /jchunk AJAX route to fetch specific lines of a given |
| 28 | - artifact. The first argument must be an Object with a minimum of | |
| 29 | - these properties: | |
| 28 | + artifact. The first argument must be an Object with these | |
| 29 | + properties: | |
| 30 | 30 | |
| 31 | 31 | { |
| 32 | 32 | name: full hash of the target file, |
| 33 | - from: first line number of the file to fetch (inclusive), | |
| 34 | - to: last line number of the file to fetch (inclusive) | |
| 33 | + from: first 1-based line number of the file to fetch (inclusive), | |
| 34 | + to: last 1-based line number of the file to fetch (inclusive) | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | onload and onerror are optional callback functions to be called |
| 38 | - on success resp. error, as documented for fossil.fetch(). Note | |
| 39 | - that onload is ostensibly optional but this function is not of | |
| 40 | - much use without an onload handler. Conversely, the default | |
| 38 | + on success resp. error, as documented for window.fossil.fetch(). | |
| 39 | + Note that onload is ostensibly optional but this function is not | |
| 40 | + of much use without an onload handler. Conversely, the default | |
| 41 | 41 | onerror handler is often customized on a per-page basis to send |
| 42 | 42 | the error output somewhere where the user can see it. |
| 43 | + | |
| 44 | + The response, on success, will be an array of strings, each entry | |
| 45 | + being one line from the requested artifact. If the 'to' line is | |
| 46 | + greater than the length of the file, the array will be shorter | |
| 47 | + than (to-from) lines. | |
| 43 | 48 | |
| 44 | 49 | The /jchunk route reports errors via JSON objects with |
| 45 | 50 | an "error" string property describing the problem. |
| 46 | 51 | |
| 47 | - This is an async operation. Returns window.fossil. | |
| 52 | + This is an async operation. Returns this object. | |
| 48 | 53 | */ |
| 49 | 54 | F.fetchArtifactLines = function(urlParams, onload, onerror){ |
| 50 | 55 | const opt = {urlParams}; |
| 51 | 56 | if(onload) opt.onload = onload; |
| 52 | 57 | if(onerror) opt.onerror = onerror; |
| 53 | - F.fetch('jchunk', opt); | |
| 54 | - return F; | |
| 58 | + return this.fetch('jchunk', opt); | |
| 55 | 59 | }; |
| 56 | 60 | }); |
| 57 | 61 | |
| 58 | 62 | /** |
| 59 | 63 | 2021-09-07: refactoring the following for use in the higher-level |
| 60 | 64 |
| --- src/fossil.diff.js | |
| +++ src/fossil.diff.js | |
| @@ -23,37 +23,41 @@ | |
| 23 | window.fossil.onPageLoad(function(){ |
| 24 | const F = window.fossil, D = F.dom; |
| 25 | |
| 26 | /** |
| 27 | Uses the /jchunk AJAX route to fetch specific lines of a given |
| 28 | artifact. The first argument must be an Object with a minimum of |
| 29 | these properties: |
| 30 | |
| 31 | { |
| 32 | name: full hash of the target file, |
| 33 | from: first line number of the file to fetch (inclusive), |
| 34 | to: last line number of the file to fetch (inclusive) |
| 35 | } |
| 36 | |
| 37 | onload and onerror are optional callback functions to be called |
| 38 | on success resp. error, as documented for fossil.fetch(). Note |
| 39 | that onload is ostensibly optional but this function is not of |
| 40 | much use without an onload handler. Conversely, the default |
| 41 | onerror handler is often customized on a per-page basis to send |
| 42 | the error output somewhere where the user can see it. |
| 43 | |
| 44 | The /jchunk route reports errors via JSON objects with |
| 45 | an "error" string property describing the problem. |
| 46 | |
| 47 | This is an async operation. Returns window.fossil. |
| 48 | */ |
| 49 | F.fetchArtifactLines = function(urlParams, onload, onerror){ |
| 50 | const opt = {urlParams}; |
| 51 | if(onload) opt.onload = onload; |
| 52 | if(onerror) opt.onerror = onerror; |
| 53 | F.fetch('jchunk', opt); |
| 54 | return F; |
| 55 | }; |
| 56 | }); |
| 57 | |
| 58 | /** |
| 59 | 2021-09-07: refactoring the following for use in the higher-level |
| 60 |
| --- src/fossil.diff.js | |
| +++ src/fossil.diff.js | |
| @@ -23,37 +23,41 @@ | |
| 23 | window.fossil.onPageLoad(function(){ |
| 24 | const F = window.fossil, D = F.dom; |
| 25 | |
| 26 | /** |
| 27 | Uses the /jchunk AJAX route to fetch specific lines of a given |
| 28 | artifact. The first argument must be an Object with these |
| 29 | properties: |
| 30 | |
| 31 | { |
| 32 | name: full hash of the target file, |
| 33 | from: first 1-based line number of the file to fetch (inclusive), |
| 34 | to: last 1-based line number of the file to fetch (inclusive) |
| 35 | } |
| 36 | |
| 37 | onload and onerror are optional callback functions to be called |
| 38 | on success resp. error, as documented for window.fossil.fetch(). |
| 39 | Note that onload is ostensibly optional but this function is not |
| 40 | of much use without an onload handler. Conversely, the default |
| 41 | onerror handler is often customized on a per-page basis to send |
| 42 | the error output somewhere where the user can see it. |
| 43 | |
| 44 | The response, on success, will be an array of strings, each entry |
| 45 | being one line from the requested artifact. If the 'to' line is |
| 46 | greater than the length of the file, the array will be shorter |
| 47 | than (to-from) lines. |
| 48 | |
| 49 | The /jchunk route reports errors via JSON objects with |
| 50 | an "error" string property describing the problem. |
| 51 | |
| 52 | This is an async operation. Returns this object. |
| 53 | */ |
| 54 | F.fetchArtifactLines = function(urlParams, onload, onerror){ |
| 55 | const opt = {urlParams}; |
| 56 | if(onload) opt.onload = onload; |
| 57 | if(onerror) opt.onerror = onerror; |
| 58 | return this.fetch('jchunk', opt); |
| 59 | }; |
| 60 | }); |
| 61 | |
| 62 | /** |
| 63 | 2021-09-07: refactoring the following for use in the higher-level |
| 64 |
+10
-5
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -1893,13 +1893,15 @@ | ||
| 1893 | 1893 | ** **Warning:** This is an internal-use-only interface that is subject to |
| 1894 | 1894 | ** change at any moment. External application should not use this interface |
| 1895 | 1895 | ** since the application will break when this interface changes, and this |
| 1896 | 1896 | ** interface will undoubtedly change. |
| 1897 | 1897 | ** |
| 1898 | -** This page is intended to be used in an XHR from javascript on a diff | |
| 1899 | -** page, to return unseen context to fill in additional context when the | |
| 1900 | -** user clicks on the appropriate button. | |
| 1898 | +** This page is intended to be used in an XHR from javascript on a | |
| 1899 | +** diff page, to return unseen context to fill in additional context | |
| 1900 | +** when the user clicks on the appropriate button. The response is | |
| 1901 | +** always in JSON form and errors are reported as documented for | |
| 1902 | +** ajax_route_error(). | |
| 1901 | 1903 | */ |
| 1902 | 1904 | void jtext_page(void){ |
| 1903 | 1905 | int rid = 0; |
| 1904 | 1906 | const char *zName = PD("name", ""); |
| 1905 | 1907 | int iFrom = atoi(PD("from","0")); |
| @@ -1910,11 +1912,14 @@ | ||
| 1910 | 1912 | Blob content; |
| 1911 | 1913 | Blob line; |
| 1912 | 1914 | Blob *pOut; |
| 1913 | 1915 | |
| 1914 | 1916 | login_check_credentials(); |
| 1915 | - if( !g.perm.Read ){ login_needed(g.anon.Read); return; } | |
| 1917 | + if( !g.perm.Read ){ | |
| 1918 | + ajax_route_error(403, "Access requires Read permissions."); | |
| 1919 | + return; | |
| 1920 | + } | |
| 1916 | 1921 | #if 0 |
| 1917 | 1922 | /* Re-enable this block once this code is integrated somewhere into |
| 1918 | 1923 | the UI. */ |
| 1919 | 1924 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zName); |
| 1920 | 1925 | if( rid==0 ){ |
| @@ -1927,11 +1932,11 @@ | ||
| 1927 | 1932 | rid = symbolic_name_to_rid(zName, "*"); |
| 1928 | 1933 | if( rid==0 ){ |
| 1929 | 1934 | ajax_route_error(404, "Unknown artifact: %h", zName); |
| 1930 | 1935 | return; |
| 1931 | 1936 | }else if( rid<0 ){ |
| 1932 | - ajax_route_error(404, "Ambiguous artifact name: %h", zName); | |
| 1937 | + ajax_route_error(418, "Ambiguous artifact name: %h", zName); | |
| 1933 | 1938 | return; |
| 1934 | 1939 | } |
| 1935 | 1940 | #endif |
| 1936 | 1941 | if( iFrom<1 || iTo<iFrom ){ |
| 1937 | 1942 | ajax_route_error(500, "Invalid line range from=%d, to=%d.", |
| 1938 | 1943 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1893,13 +1893,15 @@ | |
| 1893 | ** **Warning:** This is an internal-use-only interface that is subject to |
| 1894 | ** change at any moment. External application should not use this interface |
| 1895 | ** since the application will break when this interface changes, and this |
| 1896 | ** interface will undoubtedly change. |
| 1897 | ** |
| 1898 | ** This page is intended to be used in an XHR from javascript on a diff |
| 1899 | ** page, to return unseen context to fill in additional context when the |
| 1900 | ** user clicks on the appropriate button. |
| 1901 | */ |
| 1902 | void jtext_page(void){ |
| 1903 | int rid = 0; |
| 1904 | const char *zName = PD("name", ""); |
| 1905 | int iFrom = atoi(PD("from","0")); |
| @@ -1910,11 +1912,14 @@ | |
| 1910 | Blob content; |
| 1911 | Blob line; |
| 1912 | Blob *pOut; |
| 1913 | |
| 1914 | login_check_credentials(); |
| 1915 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1916 | #if 0 |
| 1917 | /* Re-enable this block once this code is integrated somewhere into |
| 1918 | the UI. */ |
| 1919 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zName); |
| 1920 | if( rid==0 ){ |
| @@ -1927,11 +1932,11 @@ | |
| 1927 | rid = symbolic_name_to_rid(zName, "*"); |
| 1928 | if( rid==0 ){ |
| 1929 | ajax_route_error(404, "Unknown artifact: %h", zName); |
| 1930 | return; |
| 1931 | }else if( rid<0 ){ |
| 1932 | ajax_route_error(404, "Ambiguous artifact name: %h", zName); |
| 1933 | return; |
| 1934 | } |
| 1935 | #endif |
| 1936 | if( iFrom<1 || iTo<iFrom ){ |
| 1937 | ajax_route_error(500, "Invalid line range from=%d, to=%d.", |
| 1938 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1893,13 +1893,15 @@ | |
| 1893 | ** **Warning:** This is an internal-use-only interface that is subject to |
| 1894 | ** change at any moment. External application should not use this interface |
| 1895 | ** since the application will break when this interface changes, and this |
| 1896 | ** interface will undoubtedly change. |
| 1897 | ** |
| 1898 | ** This page is intended to be used in an XHR from javascript on a |
| 1899 | ** diff page, to return unseen context to fill in additional context |
| 1900 | ** when the user clicks on the appropriate button. The response is |
| 1901 | ** always in JSON form and errors are reported as documented for |
| 1902 | ** ajax_route_error(). |
| 1903 | */ |
| 1904 | void jtext_page(void){ |
| 1905 | int rid = 0; |
| 1906 | const char *zName = PD("name", ""); |
| 1907 | int iFrom = atoi(PD("from","0")); |
| @@ -1910,11 +1912,14 @@ | |
| 1912 | Blob content; |
| 1913 | Blob line; |
| 1914 | Blob *pOut; |
| 1915 | |
| 1916 | login_check_credentials(); |
| 1917 | if( !g.perm.Read ){ |
| 1918 | ajax_route_error(403, "Access requires Read permissions."); |
| 1919 | return; |
| 1920 | } |
| 1921 | #if 0 |
| 1922 | /* Re-enable this block once this code is integrated somewhere into |
| 1923 | the UI. */ |
| 1924 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zName); |
| 1925 | if( rid==0 ){ |
| @@ -1927,11 +1932,11 @@ | |
| 1932 | rid = symbolic_name_to_rid(zName, "*"); |
| 1933 | if( rid==0 ){ |
| 1934 | ajax_route_error(404, "Unknown artifact: %h", zName); |
| 1935 | return; |
| 1936 | }else if( rid<0 ){ |
| 1937 | ajax_route_error(418, "Ambiguous artifact name: %h", zName); |
| 1938 | return; |
| 1939 | } |
| 1940 | #endif |
| 1941 | if( iFrom<1 || iTo<iFrom ){ |
| 1942 | ajax_route_error(500, "Invalid line range from=%d, to=%d.", |
| 1943 |