Fossil SCM

/jchunk now always uses a JSON response, even for permissions problems. Doc improvements for the jchunk interface.

stephan 2021-09-08 18:42 diff-js-refactoring
Commit 1fec5f4abc3b2a478ae442b0f6807038afa9e56b41358ebd885409836ef52ecf
2 files changed +14 -10 +10 -5
+14 -10
--- src/fossil.diff.js
+++ src/fossil.diff.js
@@ -23,37 +23,41 @@
2323
window.fossil.onPageLoad(function(){
2424
const F = window.fossil, D = F.dom;
2525
2626
/**
2727
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:
3030
3131
{
3232
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)
3535
}
3636
3737
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
4141
onerror handler is often customized on a per-page basis to send
4242
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.
4348
4449
The /jchunk route reports errors via JSON objects with
4550
an "error" string property describing the problem.
4651
47
- This is an async operation. Returns window.fossil.
52
+ This is an async operation. Returns this object.
4853
*/
4954
F.fetchArtifactLines = function(urlParams, onload, onerror){
5055
const opt = {urlParams};
5156
if(onload) opt.onload = onload;
5257
if(onerror) opt.onerror = onerror;
53
- F.fetch('jchunk', opt);
54
- return F;
58
+ return this.fetch('jchunk', opt);
5559
};
5660
});
5761
5862
/**
5963
2021-09-07: refactoring the following for use in the higher-level
6064
--- 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 @@
18931893
** **Warning:** This is an internal-use-only interface that is subject to
18941894
** change at any moment. External application should not use this interface
18951895
** since the application will break when this interface changes, and this
18961896
** interface will undoubtedly change.
18971897
**
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().
19011903
*/
19021904
void jtext_page(void){
19031905
int rid = 0;
19041906
const char *zName = PD("name", "");
19051907
int iFrom = atoi(PD("from","0"));
@@ -1910,11 +1912,14 @@
19101912
Blob content;
19111913
Blob line;
19121914
Blob *pOut;
19131915
19141916
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
+ }
19161921
#if 0
19171922
/* Re-enable this block once this code is integrated somewhere into
19181923
the UI. */
19191924
rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zName);
19201925
if( rid==0 ){
@@ -1927,11 +1932,11 @@
19271932
rid = symbolic_name_to_rid(zName, "*");
19281933
if( rid==0 ){
19291934
ajax_route_error(404, "Unknown artifact: %h", zName);
19301935
return;
19311936
}else if( rid<0 ){
1932
- ajax_route_error(404, "Ambiguous artifact name: %h", zName);
1937
+ ajax_route_error(418, "Ambiguous artifact name: %h", zName);
19331938
return;
19341939
}
19351940
#endif
19361941
if( iFrom<1 || iTo<iFrom ){
19371942
ajax_route_error(500, "Invalid line range from=%d, to=%d.",
19381943
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button